I'm trying to create a android menu which should be build dynamically inside a Google Glass app. Therefore I have to arrays which contain the diffent kinds of objects which should be displayed in the menu. The menu should look like the following:
- Menu1
- Option1
- Option2
- Option3
- Menu2
- Option1
- Option2
- Menu3
- Menu4
I've already build up the menu structure with this code:
public boolean onCreateOptionsMenu(Menu menu) {
menu.clear();
SubMenu damageCodes = menu.addSubMenu(R.string.chooseDamageCode).setIcon(R.drawable.ic_document_50);
int i = 0;
for(Damagecode d : this.mDamagecodes){
damageCodes.add(0, Menu.NONE, i, d.getCotext());
i++;
}
SubMenu priorities = menu.addSubMenu(R.string.choosePriority).setIcon(R.drawable.ic_document_50);
i = 0;
for(Priority p : this.mPriorities){
priorities.add(1, Menu.NONE, i, p.getPriokx());
i++;
}
menu.add(3, Menu.NONE, Menu.NONE, R.string.setConfirmationText).setIcon(R.drawable.ic_pen_50);
menu.add(4, Menu.NONE, Menu.NONE, R.string.backToTplnr_equipment).setIcon(R.drawable.ic_reply_50);
getMenuInflater().inflate(R.menu.create_notification, menu);
return true;
}
I know that the method
@Override
public boolean onMenuItemSelected(int featureId, MenuItem item) {
}
is called when a menuitem is selected but the question right now is how to get the selected item?
Just put a switch inside the onMenuItemSelected:
Hope this helps