Updating Menu Items Dynamically
This lets you dynamically disable/enable Menu Items, set visibility, and modify text.
Note that the onPrepareOptionsMenu method is triggered whenever the menu button is clicked, the overflow menu displayed, or the Action Bar is created.
To modify Menu Items dynamically, you can either record a reference to them from within the onCreateOptionsMenu method when they’re created, or you can use the findItem method on the Menu object, where onPrepareOptionsMenu is overridden.
Modifying Menu Items dynamically
@Override
public boolean onPrepareOptionsMenu(Menu menu)
{
super.onPrepareOptionsMenu(menu);
MenuItem menuItem = menu.findItem(MENU_ITEM);
[ ... modify Menu Items ... ]
[ ... modify Menu Items ... ]
return true;
}
No comments:
Post a Comment