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, 0);
var mi_appWorld = new, 1, "Open App World", appWorld);
var mi_about = new, 2, "About", showAbout);
var mi_reload = new, 3, "Refresh", reloadPage);
var mi_middle = new, 4);
var mi_share = new, 5, "Share ...", shareApp);
var mi_bottom = new, 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 ( {;

//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.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.