android - How do I find out which is clicked on my ActionBar MenuItem? -
how know if item clicked?
since understand if, event a occur following button of actionbar clicked, how implement such thing?
the method creating in onoptionsselected(menuitem item)
method works onclicklistener
buttons.
it asks id of menu item trough method getitemid()
, handles each item specific click. example starting settingsactivity, when settings menu clicked
but check out tutorial of comments further information.
the code need implement it:
@override public boolean oncreateoptionsmenu(menu menu) { // inflate menu items use in action bar menuinflater inflater = getmenuinflater(); inflater.inflate(r.menu.main_activity_actions, menu); return super.oncreateoptionsmenu(menu); } @override public boolean onoptionsitemselected(menuitem item) { // handle presses on action bar items switch (item.getitemid()) { case r.id.action_search: opensearch(); return true; case r.id.action_settings: opensettings(); return true; default: return super.onoptionsitemselected(item); }
but can found in tutorial