tags:

views:

35

answers:

1

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?

+2  A: 

Override this onPrepareOptionsMenu(Menu menu)

@Override
    public boolean onPrepareOptionsMenu(Menu menu) {

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

        if (item != null) {
         item.setVisible (shouldIShowThisItem)
        }
}
Alex Volovoy
That worked great. To anyone else doing this, before you can change the menu items in onPrepareOptionsMenu you need to do a menu.clear() to clear out the current stuff.
pcm2a
You don't need to clear the menu if you're only changing existing items. If you're regenerating or reinflating an entirely new menu you may want to.
adamp
I was unable to change the menu items without clearing and recreating it. I tried getting an individual item with menu.getPositon() but when I changed the Title the changes were not reflected in the menu.
pcm2a