0

I am trying to modify the title of menu item on google glass dynamically. As there is no hardware menu button and My activity is themed NoActionBarFullScreen, creating and initializing the Menu menu item in onCreateOptionsMenu always give null value because onCreateOptionsMenu never called. So how to do that ?

@Override
public boolean onCreateOptionsMenu(Menu menu) {
    getMenuInflater().inflate(R.menu.gatt_services, menu);
    if (!init) {
// I want to do this outside of this function also
        menu.findItem(R.id.menu_connect).setTitle("Connect");           }
 else {
        menu.findItem(R.id.menu_connect).setTitle("Disconnect");
    }
// so I initialized this variable here
    this.menu = menu; // but this is always null
    return true;
}

MenuItem connetItem = menu.findItem(R.id.menu_connect); // App crashes

So how do i access this menu item and change its title?

Cyph3rCod3r
  • 1,978
  • 23
  • 33
  • Did you try [OnPrepareOptionsMenu](http://developer.android.com/reference/android/app/Activity.html#onPrepareOptionsMenu%28android.view.Menu%29) ? – NitroG42 May 06 '14 at 07:30
  • yes I do intialize "menu" there but its always null – Cyph3rCod3r May 06 '14 at 07:33
  • We might need the full code of your activity. Do you use a Fragment ? Because the menu of a fragment could override the one of an activity. – NitroG42 May 06 '14 at 07:38
  • I am not using fragments at all. I am just using a full screen activity and I have 4-5 menu items. I just want to change their(a menu item) title on a button click thats it. – Cyph3rCod3r May 06 '14 at 09:34
  • Well post your whole Activity's code. It's weird that menu is null because then getMenuInflater().inflate(R.menu.gatt_services, menu); shouldn't work, and you would not be able to see the menu in the application. – NitroG42 May 06 '14 at 11:52
  • I assume you're calling `openOptionsMenu();` to actually display the menu, as specified in https://developers.google.com/glass/develop/gdk/immersions#displaying_the_menu ? – Sean Barbeau May 07 '14 at 15:22
  • yes i am calling that – Cyph3rCod3r May 08 '14 at 07:07

0 Answers0