Issue
In my project i have activity with options menu. I override onOptionsItemSelected
method and add my handlers to menu items (switch-case block). But in one handler i need access to another menu item, how i can do that? findViewById doesn't work
@Override
public boolean onOptionsItemSelected(MenuItem item) {
switch (item.getItemId()) {
case R.id.visit:
//how to access another MenuItem from here?
return true;
}
...
Solution
When creating your menu items, you could put the MenuItem
you want to check in an attribute (i.e. one of the private
fields of your class). This way, when you go into your method, you'll be able toacces the other menu item.
Answered By - Valentin Rocher
Answer Checked By - Clifford M. (JavaFixing Volunteer)