I have menu in my App. I need to check for the which menu item been selected by the user and take appropriate action. I did this as,
@Override
public boolean onOptionsItemSelected(MenuItem menuitem){
String title = menuitem.getTitle().toString();
int itemId = menuitem.getItemId();
switch(itemId){
case 2131296257:
-----------------;
break;
case 2131296258:
------------------;
break;
}
But these MenuItem Id’s are getting changed each time I run my App. Now I thought to compare the menuTitle with hard coded string values like ,
String title = menuitem.getTitle().toString();
if(title.equals("Settings..")){
-------------
-------------
-------------
}
But I don’t think it’s a good practice. But I guess I can do the same using the menu titles defined in strings.xml. But I am not sure how to use this…. (like R.string…..).
Can someone suggest on this please.
Thanks
Here’s an example menu named game_menu.xml:
Inflating a Menu Resource
Responding to user action
for more information click here