Friday 15 May 2015

android - Dynamic option menu --> how to get the selected item? -



android - Dynamic option menu --> how to get the selected item? -

i'm trying create android menu should build dynamically within google glass app. hence have arrays contain diffent kinds of objects should displayed in menu. menu should following:

menu1 option1 option2 option3 menu2 option1 option2 menu3 menu4

i've build menu construction code:

public boolean oncreateoptionsmenu(menu menu) { menu.clear(); submenu damagecodes = menu.addsubmenu(r.string.choosedamagecode).seticon(r.drawable.ic_document_50); int = 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); = 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); homecoming true; }

i know method

@override public boolean onmenuitemselected(int featureid, menuitem item) { }

is called when menuitem selected question right how selected item?

just set switch within onmenuitemselected:

@override public boolean onmenuitemselected(int featureid, menuitem item) { switch(item.gettitle()) { case r.string.choosedamagecode: // stuff here damagecode item break; case r.string.choosepriority: // stuff here choosepriority item break; ...same other items } }

hope helps

android google-glass google-gdk android-menu

No comments:

Post a Comment