Menu
The Menu object contains functionality for manipulating menu items for the application.
| Sample - Menu Items Example that demonstrates how to use the Menu API to create a custom application menu in a BlackBerry WebWorks application [BlackBerry Developer Resource Center]. | 
Supported Platform(s)
- BlackBerry OS 5.0+
- Ripple Emulator
| API | OS 5.0 | OS 6.0 | OS 7.0 | PlayBook | Ripple | 
|---|---|---|---|---|---|
| addMenuItem | Y | Y | Y | Y | |
| clearMenuItems | Y | Y | Y | Y | |
| getMenuItems | Y | Y | Y | Y | |
| hasMenuItem | Y | Y | Y | Y | |
| open | Y | Y | Y | Y | |
| removeMenuItem | Y | Y | Y | Y | |
| setDefaultMenuItem | Y | Y | Y | Y | 
Configuration Document Settings
To use all of the API described for this object, you must ensure the following settings are in your configuration document:
You must declare the feature element(s) below in your configuration document:
| Feature ID | OS 5.0 | OS 6.0 | OS 7.0 | PlayBook | Ripple | 
|---|---|---|---|---|---|
| <feature id="blackberry.ui.menu" /> | Y | Y | Y | Y | 
| Permission Elements (PlayBook Only) | 
|---|
| This API does not require a <permission> element to be declared in the configuration document of your BlackBerry WebWorks Application. | 
API Summary
addMenuItem
| static void addMenuItem(item : blackberry.ui.menu.MenuItem) | 
Supported Platform(s)
- BlackBerry OS 5.0+- Ripple Emulator
Description
Adds the supplied menu item to the menu.
| Parameter | Type | Description | 
|---|---|---|
| item | blackberry.ui.menu.MenuItem | The menu item to add. | 
Code Example(s)
<script type="text/javascript">
  function loadCustomMenuItemsForPage() {
    if (blackberry.ui.menu.getMenuItems().length > 0) {
      blackberry.ui.menu.clearMenuItems();
    }
    
    var item = new blackberry.ui.menu.MenuItem(false, 1, "Click Me", customMenuItemClick);
    blackberry.ui.menu.addMenuItem(item);         
  }
    function customMenuItemClick() {
      alert("user just clicked me");
    }
</script>
	
    
            clearMenuItems
| static void clearMenuItems() | 
Supported Platform(s)
- BlackBerry OS 5.0+- Ripple Emulator
Description
Removes all menu items from the current menu.
getMenuItems
| static blackberry.ui.menu.MenuItem[] getMenuItems() | 
Supported Platform(s)
- BlackBerry OS 5.0+- Ripple Emulator
Description
This method will return an array representing the menu items for the screen.
hasMenuItem
| static Boolean hasMenuItem(item : blackberry.ui.menu.MenuItem) | 
Supported Platform(s)
- BlackBerry OS 5.0+- Ripple Emulator
Description
determine whether the menu contains the specified MenuItem.
| Parameter | Type | Description | 
|---|---|---|
| item | blackberry.ui.menu.MenuItem | The menu item to be checked. | 
open
| static void open() | 
Supported Platform(s)
- BlackBerry OS 5.0+- Ripple Emulator
Description
Opens the current screen's menu.
removeMenuItem
| static void removeMenuItem(item : blackberry.ui.menu.MenuItem) | 
Supported Platform(s)
- BlackBerry OS 5.0+- Ripple Emulator
Description
Removes the specified menu item from the menu.
| Parameter | Type | Description | 
|---|---|---|
| item | blackberry.ui.menu.MenuItem | The menu item to remove. | 
setDefaultMenuItem
| static void setDefaultMenuItem(item : blackberry.ui.menu.MenuItem) | 
Supported Platform(s)
- BlackBerry OS 5.0+- Ripple Emulator
Description
Sets which item on the menu should be selected by default.
| Parameter | Type | Description | 
|---|---|---|
| item | blackberry.ui.menu.MenuItem | The menu item to set as the default. | 
            
            Documentation generated by JsDoc Toolkit 2.4.0 on Sun Dec 30 2012 13:31:18 GMT-0500 (EST)