Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to call onCreateOptionsMenu from code

Tags:

java

android

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

like image 473
user222 Avatar asked Jul 03 '13 19:07

user222


People also ask

How do you call Oncreateoptionsmenu?

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() .

What is onCreate in android?

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.


Video Answer


1 Answers

I believe you want invalidateOptionsMenu()

like image 194
tyczj Avatar answered Oct 23 '22 18:10

tyczj