Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

how to rename existing menu item?

Tags:

android

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.

like image 931
AndroiDBeginner Avatar asked Dec 31 '09 01:12

AndroiDBeginner


1 Answers

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);
}
like image 64
Christopher Orr Avatar answered Oct 24 '22 04:10

Christopher Orr