android - Changing visibility of menu items in fragment -



android - Changing visibility of menu items in fragment -

i'm trying hide menu items when fragment changed, seems not working. here im doing: defining menu , menu items:

@override public boolean oncreateoptionsmenu(menu menu) { // inflate menu items utilize in action bar menuinflater inflater = getmenuinflater(); inflater.inflate(r.menu.actionbar_sharecall, menu); actionmenu = menu; menuitem searchitem = menu.finditem(r.id.action_searchmenuitem); menuitem item = menu.finditem(r.id.action_menushare); // item.setvisible(false); // searchitem.setvisible(false); topsearch = searchitem; topshare = item; final mrshareactionprovider actionprovider = new mrshareactionprovider( this); menuitemcompat.setactionprovider(item, actionprovider); actionprovider .setsharehistoryfilename(shareactionprovider.default_share_history_file_name); actionprovider.setonsharetargetselectedlistener(this); actionprovider.setshareintent(createshareintent()); homecoming true; }

changing fragment , changing visibility:

//changing visibility topsearch.setvisible(false); frag = new syncfragment(); fragmenttransaction ft = getsupportfragmentmanager() .begintransaction(); ft.replace(r.id.fragment_content, frag); ft.commitallowingstateloss();

and syncfragment:

public class syncfragment extends mrbaseacbfragment { @override public view oncreateview(layoutinflater inflater, viewgroup container, bundle savedinstancestate) { homecoming inflater.inflate(r.layout.fragment_sync, null); } }

but after fragment changed, can still see menu item. can help me solution on how this?

i don't know why not work, seek alter visibility straight in oncreateoptionmenu.

if works, when want hide phone call invalidateoptionsmenu (or supportinvalidateoptionsmenu actionbar compat), forcefulness oncreateoptionmenu called 1 time again , can update menu if fragment there or not.

android android-fragments android-actionbar android-optionsmenu

Comments

Popular posts from this blog

xslt - DocBook 5 to PDF transform failing with error: "fo:flow" is missing child elements. Required content model: marker* -

mediawiki - How do I insert tables inside infoboxes on Wikia pages? -

Local Service User Logged into Windows -