tags:

views:

99

answers:

3

Hi guys.

Do you know how to rename existing menu ?

I can rename when press menu item. But I don't know how to access to menu item when press the button.

Please advice.

A: 

Use MenuItem.setTitle(). If this isn't what you needed, you have to be more specific.

dmazzoni
+3  A: 

It would be good if you can clarify the question a little, but each time the user presses the Menu on their Android device while inside one of your activities, the onPrepareOptionsMenu method is called. The first time the menu is shown (i.e. only once), the onCreateOptionsMenu method is called.

Basically, the onPrepareOptionsMenu method is where you should make any changes such as enabling/disabling certain menu items, or changing the menu item text depending on the circumstances.

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
Thanks for response. I've found the solution : public boolean onMenuOpened(int featureId, Menu menu) it would be fine for my case.
AndroiDBeginner
A: 

The onPrepareOptionsMenu is the proper place to make changes to menuitems.

Coach David