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,487 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:

//Add your own custom MenuItem objects to the menu:

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

//Optionally define the menu item that will receive default
// focus when the menu is opened:

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



For more Information :



  • 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: 13 members 2,205 guests
Please welcome our newest community members: