Cameron McBride
Cameron McBride

Reputation: 6799

How to make a dynamic options menu?

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?

Upvotes: 8

Views: 9706

Answers (2)

Gopi Cg
Gopi Cg

Reputation: 382

invalidateOptionsMenu();

if you want to push the menu changes use this.

Upvotes: 0

Alex Volovoy
Alex Volovoy

Reputation: 68474

Override this onPrepareOptionsMenu(Menu menu)

@Override
    public boolean onPrepareOptionsMenu(Menu menu) {

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

        if (item != null) {
         item.setVisible (shouldIShowThisItem)
        }
}

Upvotes: 23

Related Questions