Time for action – adding an Android menu
Perform the following steps for adding an Android menu:
Add a function that will define the pop-up menu:
function addMenu(win) { var activity = win.activity; activity.onCreateOptionsMenu = function(e){ var firstItem = e.menu.add({ title: 'First Item' }); firstItem.addEventListener("click", function(e) {Ti.API.debug('First Item'); }); var secondItem = e.menu.add({ title: 'Second Item'}); secondItem.addEventListener("click", function(e) {Ti.API.warn('Second Item'); }); var thirdItem = e.menu.add({ title: 'Third Item'}); thirdItem.addEventListener("click", function(e) {alert('Third Item'); }); }; }
Further down
app.js
where the windows are defined, add the highlighted code to call the function:win1.add(label1); addMenu(win1);
Run the app using the Android emulator.
What just happened?
A pop-up menu was created that is activated by pressing the menu key when Tab 1 is selected. The pop-up menu has three items and...