Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to make a dynamic options menu?

Tags:

android

The problem is that the following method gets called one time when the Menu button is pressed:

public boolean onCreateOptionsMenu(Menu menu)

How can I recreate the menu at a later time in order to change some options, disable some options, etc?

like image 972
Cameron McBride Avatar asked Sep 09 '10 21:09

Cameron McBride


1 Answers

Override this onPrepareOptionsMenu(Menu menu)

@Override
    public boolean onPrepareOptionsMenu(Menu menu) {

        MenuItem item = menu.findItem(R.id.refresh);

        if (item != null) {
         item.setVisible (shouldIShowThisItem)
        }
}
like image 142
Alex Volovoy Avatar answered Oct 10 '22 20:10

Alex Volovoy