ArrayList<String> emplist = new ArrayList<String>();
//Inside the array I add list of employee that I query from DB
SubMenu empMenu = menu.addSubMenu("Employee's Map").setIcon(R.drawable.group);
for (int i = 0; i < emplist.size(); i++) {
empMenu.add(EMPLOYEE, i, i, emplist.get(i));
}
I prefer option for user that can select name of employee then I will perform result.
So, my question is how can I get the itemId which relate to user's selecte开发者_JAVA技巧d to use in onCreateOptionsMenu(Menu menu)
Thank you for your suggestion.
You can override onOptionsItemSelected
methods in your Activity to get which menu item is selected by calling getItemId
on the menuItem
argument. Following is a sample code.
public boolean onOptionsItemSelected(MenuItem item) {
int id = item.getItemId();
// process with the item id of user selected menu.
// ...
return true
}
精彩评论