Is it possible to change the option menu items programmatically? Can anyone provide me with an example please?
Also, I want to disable certain items, so that they do
If I have to change the contents of my options menu I perform it during the onMenuOpened(). This allows me to check the running state at the very moment that the user is accessing the menu.
public boolean onMenuOpened(int featureid, Menu menu)
{
menu.clear();
if (!editable)
{
MenuItem itemAdd = menu.add(0, REASSIGN, Menu.NONE, context.getString(R.string.reassign));
MenuItem itemMod = menu.add(1, EDIT, Menu.NONE, context.getString(R.string.modify));
MenuItem itemDel = menu.add(2, DELETE, Menu.NONE, context.getString(R.string.delete));
itemAdd.setShortcut('0', 'a');
itemMod.setShortcut('1', 'm');
itemDel.setShortcut('2', 'd');
}
else
{
MenuItem itemSave = menu.add(3, SAVE, Menu.NONE, context.getString(R.string.savechanges));
itemSave.setShortcut('0', 'S');
}
return true;
}