I have been struggling with this, read the api and searched this forum, all to no avail. I am a noob, so it is likely something I am missing. Anyway, I am attempting to run the android sample on the option menu and it does not seem to work. I am running Titanium 1.2.1 on WinXP, and APIS 2.2. The code is completely contained within my app.js.
Ti.API.debug("Loading app.js"); Titanium.UI.setBackgroundColor('#000'); Ti.API.debug("create default window"); var win = Titanium.UI.createWindow({ title:'Win', backgroundColor:'#000' }); Ti.API.debug("Creating the Android Main menu items"); //CODE EXAMPLE - BEGIN - http://developer.appcelerator.com/apidoc/mobile/latest/Titanium.UI.Android.OptionMenu-module var menu = Titanium.UI.Android.OptionMenu.createMenu(); var item1 = Titanium.UI.Android.OptionMenu.createMenuItem({ title : 'Item 1', icon : '/images/item1.png' }); item1.addEventListener('click', function(){ Ti.UI.createAlertDialog({ title : 'You clicked Item 1'}).show(); }); var item2 = Titanium.UI.Android.OptionMenu.createMenuItem({ title : 'Refresh', icon : '/images/refresh.png' }); item2.addEventListener('click', function(){ Ti.UI.createAlertDialog({ title : 'You clicked Refresh'}).show(); }); menu.add(item1); menu.add(item2); // Set the menu on the current heavyweight window. A heavyweight window maps to an Android // Activity. To create a heavyweight window, specify one or more of [**fullscreen**,**navBarHidden**,**modal**] to createWindow. Titanium.UI.Android.OptionMenu.setMenu(menu); // CODE EXAMPLE - END Ti.API.debug("opening full screen window"); win.open({fullscreen:true});As you can see, the bulk of this code is straight out of the sample referenced. This problem is extremely frustrating and is completely blocking my ability to proceed. It appears many people have problems with this, but if resolved, it is not clear to me what the resolution is. Being such a fundamental thing, I have to believe it is me, not Titanium, that is the problem.
3 Answers
Accepted Answer
Take all of this code
var menu = Titanium.UI.Android.OptionMenu.createMenu(); var item1 = Titanium.UI.Android.OptionMenu.createMenuItem({ title : 'Item 1', icon : '/images/item1.png' }); item1.addEventListener('click', function(){ Ti.UI.createAlertDialog({ title : 'You clicked Item 1'}).show(); }); var item2 = Titanium.UI.Android.OptionMenu.createMenuItem({ title : 'Refresh', icon : '/images/refresh.png' }); item2.addEventListener('click', function(){ Ti.UI.createAlertDialog({ title : 'You clicked Refresh'}).show(); }); menu.add(item1); menu.add(item2); // Set the menu on the current heavyweight window. A heavyweight window maps to an Android // Activity. To create a heavyweight window, specify one or more of [**fullscreen**,**navBarHidden**,**modal**] to createWindow. Titanium.UI.Android.OptionMenu.setMenu(menu); // CODE EXAMPLE - ENDand put it in it's own JS file (e.g.
winmenu.js). Modify your app.js createWindow args to be.
var win = Titanium.UI.createWindow({ title:'Win', backgroundColor:'#000', url: 'winmenu.js', navBarHidden : false });Set one of the three parameters:
navBarHidden, fullscreen, or modal to a value. This will force the creation of an Android Activity. Menu's are associated with Activities. We are looking at ways to restructure so that this technique/workaround isn't required, especially the hidden sideeffect of setting any of those parameters forces the creation of a "heavyweight window".
You have to create and .setMenu on each page you want the menu to appear. I believe that app.js in and of itself isn't considered a window, despite the fact that you're opening one from there. Try creating your window based on a .js file and create and .setMenu in there.
Hi,
Thank you for the response. I am trying out this function to and followed your advice. I used the code from the API documentation in several JS files where I create a window. I also made sure that the window got the fullscreen property. But this does not work.
The documentation seems not to be completely covered, and no examples are available in the Kitchen sink application.
Any ideas on how to make this work?
Your Answer
Think you can help? Login to answer this question!