Android Menu not working no matter what I do, where am I going wrong?

You must Login before you can answer or comment on any questions.

I'm trying to attach a menu system to my windows, and I've tried every permutation of adding a menu to my windows that I can find through a google search and the Q&A area. Not sure what Im doing wrong for this to not work, but here is the code Im using.

(BTW Im using 1.8.0.1 from the continuous builds)

var w = Titanium.UI.createWindow({
        backgroundColor:'#131313',
        barColor:'#111',
    });
 
w.activity.onCreateOptionsMenu = function(e){
                                var menu = e.menu;
 
                                var m1 = menu.add({
                                        title: 'Home'
                                });
                                m1.setIcon('images/android_menu_home.png');
                                m1.addEventListener('singletap', function(e){
                                        Titanium.App.fireEvent('app:go:home');
                                });
 
                                var m2 = menu.add({
                                        title: 'Activity Feed'
                                });
                                m2.setIcon('images/android_menu_feed.png');
                                m2.addEventListener('singletap', function(e){
                                        Titanium.App.fireEvent('app:android:feed');
                                });
                        };
 
w.open({modal:true});

— asked 2 years ago by C H
0 Comments

4 Answers

Accepted Answer

This is a regression in 1.8.0.1 which is unstable. Watch TIMOB-6359 to see when a fix comes available.

Hi CH

I am running your code beautifully. I am using 1.7.5 Android 2.3.6 Google APIs

Probably due to SDK version you use

Try this code :

// Associated directly with an activity
activity = Ti.Android.currentActivity;
activity.onCreateOptionsMenu = function(e) {
    var menu = e.menu;
    var menuItem = menu.add({ title: "Item 1" });
    menuItem.setIcon("item1.png");
    menuItem.addEventListener("click", function(e) {
        // do something when the menu item is tapped
    });
};
 
// or with your heavyweight window, set here with navBarHidden
var win = Titanium.UI.createWindow({
    navBarHidden: false,
    activity : {
        onCreateOptionsMenu : function(e) {
            var menu = e.menu;
            var menuItem = menu.add({ title : 'Item 1' });
            menuItem.setIcon("item1.png");
            menuItem.addEventListener('click', function(e) {
                // do something when the menu item is tapped
            });
        }
    }

and if u want to save memory and increase the efficiency of the application then u must try onPrepareOptionMenu, bcoz it works on the same object of onCreateOptionMenu.

Ive tried this for different views and different windows and it is working fine.

Your Answer

Think you can help? Login to answer this question!