Android OptionMenu missing from 1.5 CI builds
I'm trying to use the Android OptionMenu in the latest 1.5 CI build with the same code that worked in 1.4:
function createMenu() {
var menu = null;
if (isAndroid) {
menu = Ti.UI.Android.OptionMenu.createMenu();
}
//refresh button.
var btnRefresh = null;
if (!isAndroid) {
btnRefresh = new Button({ title: 'Refresh', style: Ti.UI.iPhone.SystemButtonStyle.BORDERED });
} else {
btnRefresh = Ti.UI.Android.OptionMenu.createMenuItem({ title: "Refresh" });
}
btnRefresh.addEventListener('click', function () { getVehicles(true); });
//add menu to toolbar.
if (!isAndroid) {
var flexSpace = new Button({ systemButton: Ti.UI.iPhone.SystemButton.FLEXIBLE_SPACE });
win.setToolbar([flexSpace, btnRefresh, flexSpace]);
} else {
menu.add(btnRefresh);
Ti.UI.Android.OptionMenu.setMenu(menu);
}
}
However it errors on OptionMenu.createMenu():
TypeError: Cannot find function createMenu in object [Ti.Android.OptionMenu]
Is this something that was left out on accident or is there new syntax for creating android menus now?
1 Answer
-
Accepted Answer
I had to remove that API. I'm in the process of documenting the new one. If you look at the updated KS example map_view.js you can see how I reworked it for the new API.
Basically, two callbacks are exposed on
Ti.Android.currentActivity
.onCreateOptionsMenu
andonPrepareOptionsMenu
. These map one to one with the underlying methods on the AndroidActivity
class.onCreateOptionsMenu
is only called once and only in response to the menu button being pressed.onPrepareOptionsMenu
is called each time before the menu is shown to the user. The menuproxy
is passed in the argument ase.menu
it is ok to hold onto this proxy outside of the method for the lifetime of the activity (heavyweight window). AMenuItem
is created viaadd
on the menu proxy. Look at line 203. Notice how I capture the proxy and store it so I can wire up the handlers in thewireClickHandlers()
method which can be used for both iPhone and Android becauseMenuItems
andButtons
respond to the click event.It's not shown in the example, but to set an icon add a menu item then
menu.setIcon(path-to-icon)