I want to get a menu item to use the .setChecked()
. But this should be in another function than the onOptionsItemSelected(MenuItem item)
. So I tried it with findViewById()
but then I mentioned that this won't work^^ I googled but I can only find examples where they user it in the onOptionsItemSelected function and can use the item
object. Is there any possibility to get the menu item like findViewById
?
I want to get a menu item to use the .setChecked(). But this should be in another function than the onOptionsItemSelected(MenuItem item)
My first idea is to create "copy" of your Menu
and then you have access to its child items.
@Override
public boolean onCreateOptionsMenu(Menu menu) {
this.menuCopy = menu;
new MenuInflater(<context>).inflate(layout, this.menuCopy);
return super.onCreateOptionsMenu(this.menuCopy);
}
And then you can use two methods:
menu.getItem()
it returns menu item at the given index menu.findItem()
it returns menu item with a particular identifier
The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.