I want to call onCreateOptionsMenu from the code because if i use:
menu.setGroupEnabled(0, false);
With:
public Menu menu;
public boolean onCreateOptionsMenu(Menu menu) {
this.menu = menu;
menu.add(0,0,0,"Option");
return true;
}
It doesn't work if the user never pressed menu button. How can I do that?
Thanks
PS: If this is a bad practice let me know
On Android 3.0 and higher, the options menu is considered to always be open when menu items are presented in the action bar. When an event occurs and you want to perform a menu update, you must call invalidateOptionsMenu() to request that the system call onPrepareOptionsMenu() .
Android App Development for Beginners onCreate() is called when the when the activity is first created. onStart() is called when the activity is becoming visible to the user.
I believe you want invalidateOptionsMenu()
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With