It would be nice if you could clarify this question a bit, but every time the user presses the Menu button on his Android device, while inside one of your actions, the onPrepareOptionsMenu method is onPrepareOptionsMenu . The first time the menu is displayed (i.e., only once), the onCreateOptionsMenu method is onCreateOptionsMenu .
Basically, the onPrepareOptionsMenu method is where you have to make any changes, such as enabling / disabling certain menu items or changing the text of a menu item as the case may be.
As an example:
@Override public boolean onPrepareOptionsMenu(Menu menu) { // Check current message count boolean haveMessages = mMessageCount != 0; // Set 'delete' menu item state depending on count MenuItem deleteItem = menu.findItem(R.id.menu_delete); deleteItem.setTitle(haveMessages ? R.string.delete : R.string.no_messages); deleteItem.setEnabled(haveMessages); return super.onPrepareOptionsMenu(menu); }
Christopher orr
source share