android - Different menu for different Fragment Tabs -


description: 1) have activity contains 1 fragment. replace fragment menu. (first level) 2) 1 of fragments tabfragments. contains 1 fragments fragment can replace when user click on tab. (second level)

i use android on 4.0.

my question is: how can have "general" menu rootactivity + "normal" menu tabfragment + other menu fragment inside tabfragment, in actionbar ? in fact, when switch between fragment in firstlevel, menu updated correctly, when go second level, menu keep item other second level fragment. , when come other first level fragments still have menu second level fragment.

edit :

first level fragment (tabfragment)

@override     public void oncreateoptionsmenu(menu menu, menuinflater inflater) {         inflater.inflate(r.menu.menu_intervention, menu);         super.oncreateoptionsmenu(menu, inflater);         // inflate menu below;     } 

second level fragment:

@override public void oncreateoptionsmenu(menu menu, menuinflater inflater) {     super.oncreateoptionsmenu(menu, inflater);     // inflate menu below;     inflater.inflate(r.menu.menu_intervention_inventaire, menu); } 

it possible.

in fragment's oncreate method call sethasoptionsmenu(true). same child fragment.

then override oncreateoptionsmenu , onoptionsitemselected.

don't forget call super.oncreateoptionsmenu fragments.

put common menu items in activity. , other items in appropriate fragment fragment.

edit: should use childfragmentmanager child fragments. it's available in support library.


Comments

Popular posts from this blog

commonjs - How to write a typescript definition file for a node module that exports a function? -

openid - Okta: Failed to get authorization code through API call -

thorough guide for profiling racket code -