Titanium.Android.Menu

Object of Titanium.Android.
Platform Since
Android 1.5

Summary

The Titanium binding of an Android Menu

Code Examples

Simple menu create

activity.onCreateOptionsMenu = function(e) {
    var menu = e.menu;
    var menuItem = menu.add({ title: "Item 1" });
    menuItem.setIcon("item1.png");
    menuItem.addEventListener("click", function(e) {
        Ti.API.debug("I was clicked");
    });
};

Dynamic menu create

var win = Ti.UI.createWindow({ fullscreen: true });</p>
<p>var LOGIN = 1, LOGOUT = 2;
var loggedIn = false;
activity.onCreateOptionsMenu = function(e) {
    var menu = e.menu;
    var login = menu.add({ title: "Login", itemId: LOGIN });
    login.setIcon("login.png");
    login.addEventListener("click", function(e) {
        loggedIn = true;
    });
    var logout = menu.add({ title: "Logout", itemId: LOGOUT });
    logout.setIcon("logout.png");
    logout.addEventListener("click", function(e) {
        loggedIn = false;
    });
};</p>
<p>activity.onPrepareOptionsMenu = function(e) {
    var menu = e.menu;
    menu.findItem(LOGIN).setVisible(!loggedIn);
    menu.findItem(LOGOUT).setVisible(loggedIn);
};
win.open();

Methods

Name Summary
add

creates a Titanium.Android.MenuItem from the passed creation options.

addEventListener

Adds the specified callback as an event listener for the named event.

clear

clear all items from the menu. You should release all references you have retained to Titanium.Android.MenuItem previously created.

close

close the menu if visible

findItem

locate a Titanium.Android.MenuItem

fireEvent

Fires a synthesized event to any registered listeners.

getItem

return the Titanium.Android.MenuItem at a specific index

getItems

Gets the value of the items property.

hasVisibleItems

query for any visible menu items

removeEventListener

Removes the specified callback as an event listener for the named event.

removeGroup

remove all Titanium.Android.MenuItem with the specified groupId

removeItem

remove a specific Titanium.Android.MenuItem by the specified itemId

setGroupEnabled

enable or disable a group of Titanium.Android.MenuItem by groupId

setGroupVisible

show or hide a group of Titanium.Android.MenuItem by groupId

size

number of Titanium.Android.MenuItem in this menu

Properties

Name Type Summary
items Array<Titanium.Android.MenuItem>

array of Titanium.Android.MenuItem read-only

Events

This type has no events.