java - on OptionsMenu click listener -


i want options menu toggle sliding menu havent found standard click listener options button. onprepareoptionsmenu method fires when clicking options button? don't want use method because method gets fired when application starts up.

update: menu button (hardware button), can use event onkeyup:

public boolean onkeyup(int keycode, keyevent event) {     if (keycode == keyevent.keycode_menu) {         if (event.getaction() == keyevent.action_up)         {             log.d("onkeyup", "onkeyup");             return true;         }     }     return super.onkeyup(keycode, event); } 

note: solution below actionbar

just override onoptionsitemselected function. can listen click event on menu items , trigger actions want according case:

here example main activity class:

@override public boolean onoptionsitemselected(menuitem item){     switch(item.getitemid()) {      case r.id.menu_calendar:         maketoast("loading...");         opencalendar();         break;     case r.id.menu_search:         maketoast("loading...");         opensearch();         break;           case r.id.menu_settings:         opensettings();         break;     case r.id.menu_help:         openhelp();         break;     case r.id.menu_about:         mbackupmanager.datachanged();         openabout();         break;     }     return true; } 

Comments

Popular posts from this blog

c# - DetailsView in ASP.Net - How to add another column on the side/add a control in each row? -

javascript - firefox memory leak -

Trying to import CSV file to a SQL Server database using asp.net and c# - can't find what I'm missing -