android - Menu different for each tab -


i read possible display different menu each tab on guide.

i have 3 tabs initialized in mainactivity. if call onprepareoptionsmenu() or oncreateoptionsmenu() in each included activity, never executed. succeed in displaying menu on mainactivity's initialization...

mainactivity:

public boolean oncreateoptionsmenu(menu menu) {     menuinflater inflater = getmenuinflater();     inflater.inflate(r.layout.menu_tab_1, menu);     return true; } 

this menu shown. 1 of tabactivities:

@override public boolean onprepareoptionsmenu(menu menu) {     menu.clear();     menuinflater inflater = getmenuinflater();     inflater.inflate(r.layout.menu_tab_2, menu);     return true; } 

this menu not refreshed when change tab. tried multiple combinations (oncreate / onprepare, override...) without success.

how properly? thanks

you have 2 options this.

first, can override onkeydown method, , detect when user presses menu, , instead of letting main activity handle it, dispatch event active tab activity.

else, can use fragments instead of activities inside tab host. fragment mechanism great combine options menus multiple source (usually 1 activity , 1 or more fragments).


Comments

Popular posts from this blog

java - Play! framework 2.0: How to display multiple image? -

gmail - Is there any documentation for read-only access to the Google Contacts API? -

php - Controller/JToolBar not working in Joomla 2.5 -