Android Fragments - How to change the ActionBar on a different fragment? -


i have 3 page fragment in app, need each fragment have different actionbar. 1 fragment have set current code in oncreateview method adds in edittext actionbar:

    //mainactivitycontext context main activity (this fragment file)     actionbar actionbar = mainactivitycontext.getactionbar();     // add custom view action bar     actionbar.setcustomview(r.layout.actionbar_view);     search = (edittext) actionbar.getcustomview().findviewbyid(r.id.searchfield);     actionbar.setdisplayoptions(actionbar.display_show_custom             | actionbar.display_show_home); 

yet edittext stays persistent throughout of actionbar menus. want on one. have tried everything, menu.clear();, sethasoptionsmenu(true);, inflater.inflate(r.menu.different_file, menu);, nothing has worked.

any help?

there approach go situation:

on each fragment's onactivitycreated() method call sethasoptionsmenu(true);

@override public void onactivitycreated(bundle savedinstancestate) {     super.onactivitycreated(savedinstancestate);     sethasoptionsmenu(true); } 

now can override oncreateoptionsmenu() , onoptionsitemselected() inside each fragment.

and dont forget call getactivity().supportinvalidateoptionsmenu(); inside onresume() of fragment.

i think this sample google helpful.


Comments

Popular posts from this blog

php - Submit Form Data without Reloading page -

linux - Rails running on virtual machine in Windows -

php - $params->set Array between square bracket -