Welcome!

Welcome to the official BlackBerry Support Community Forums.

This is your resource to discuss support topics with your peers, and learn from each other.

inside custom component

Web and WebWorks Development

Adding Menu Items using the BlackBerry WebWorks SDK

by Retired on ‎07-29-2010 12:42 PM - edited on ‎01-07-2011 08:15 AM by Retired (12,251 Views)

This article applies to BlackBerry® device applications created using the BlackBerry® WebWorks™ SDK.

 

 

The BlackBerry WebWorks API collection includes JavaScript® objects that can enhance the functionality of an application created using the BlackBerry WebWorks SDK.  This collection includes the MenuItem object which can be used to easily create contextual menus within your BlackBerry WebWorks application.

 

Adding a new item to the application menu involves the following two steps:

  1. Create an instance of the MenuItem JavaScript object
  2. Use the WebWorks Menu API to add the object to the menu.

 

The following example demonstrates how the Menu API can be used in a BlackBerry WebWorks application:

 

 

function initMenus() {
try {
//create MenuItem objects:
//
// @param isSeparator (Boolean) - true/false whether this item is a menu separator
// @param ordinal (Number) - specifies sort order within the menu. Lower ordinal values have higher position in menu.
// @param caption (String) - text to be displayed in menu for this menu item.
// @param iscallback (OnClick) - JavaScript function name to be called when user selects this menu item.
//
var mi_top = new blackberry.ui.menu.MenuItem(true, 0);
var mi_appWorld = new blackberry.ui.menu.MenuItem(false, 1, "Open App World", appWorld);
var mi_about = new blackberry.ui.menu.MenuItem(false, 2, "About", showAbout);
var mi_reload = new blackberry.ui.menu.MenuItem(false, 3, "Refresh", reloadPage);
var mi_middle = new blackberry.ui.menu.MenuItem(true, 4);
var mi_share = new blackberry.ui.menu.MenuItem(false, 5, "Share ...", shareApp);
var mi_bottom = new blackberry.ui.menu.MenuItem(true, 6);


//Optionally remove any default menu items:
//
blackberry.ui.menu.clearMenuItems();


//Add your own custom MenuItem objects to the menu:
//
blackberry.ui.menu.addMenuItem(mi_top);
blackberry.ui.menu.addMenuItem(mi_appWorld);
blackberry.ui.menu.addMenuItem(mi_about);
blackberry.ui.menu.addMenuItem(mi_reload);
blackberry.ui.menu.addMenuItem(mi_middle);
blackberry.ui.menu.addMenuItem(mi_share);


//Optionally check to see if a menu item already exists:
//
if (blackberry.ui.menu.hasMenuItem(mi_bottom)) {
blackberry.ui.menu.removeMenuItem(mi_bottom);
}
blackberry.ui.menu.addMenuItem(mi_bottom);


//Optionally define the menu item that will receive default
// focus when the menu is opened:
//
blackberry.ui.menu.setDefaultMenuItem(mi_about);

alert("Menu Items Added");
}
catch (e) {
alert('exception (addMenus): ' + e.name + '; ' + e.message);
}
}

 

 

For more Information :


 

Attachments:


  • Sample Application created using the BlackBerry WebWorks SDK that demonstrates how to use the Menu and MenuItem objects found within the WebWorks API collection.
Users Online
Currently online: 4 members 563 guests
Please welcome our newest community members: