Android - Menu items are not shown in ActionBar to start app -
i creating activity 2 fragments. implementing different menu items each fragment. having problem. sequence of error:
- tab 1 - fragment 1 -> no buttons appear on actionbar menu
- tab 2 - fragment 2 -> menu appears correctly
- tab 1 - fragment 1 -> menu displayed
until pass fragment 2 , return fragment 1 icons of actionbar not shown. can error? thank you
fragment 1
public view oncreateview(layoutinflater inflater, viewgroup container, bundle savedinstancestate) { rootview = inflater.inflate(r.layout.fragment_listado, container, false); declararobjetos(); iniciarbasedatos(); sonidos(); cargarlocalizacion(); reiniciarlistview(); pintarelementos(); sethasoptionsmenu(true); modulo.getoverflowmenu(getactivity()); activitycompat.invalidateoptionsmenu((activity) context); return rootview; } public void onprepareoptionsmenu(menu menu) { menuitemactualizarlista = menu.finditem(r.id.menuopcactualizarlista); menuitembuscar = menu.finditem(r.id.menuopcbuscar); menuitemactualizarlista.setvisible(true); menuitembuscar.setvisible(true); } public boolean onoptionsitemselected(menuitem item) { switch (item.getitemid()) { case r.id.menuopcactualizarlista: reiniciarlistview(); return true; case r.id.menuopcbuscar: cargarbuscar(); return true; default: return super.onoptionsitemselected(item); } }
menu
<menu xmlns:android="http://schemas.android.com/apk/res/android" > <item android:id="@+id/menuopcactualizarlista" android:visible="false"/> <item android:id="@+id/menuopcbuscar" android:icon="@drawable/icono_lupa" android:visible="false" android:showasaction="always" /> </menu>
you need inflate menu can show it.
@override public void oncreateoptionsmenu(menu menu, menuinflater inflater) { inflater.inflate(r.menu.mymenu, menu); } @override public void onactivitycreated(bundle savedinstancestate) { super.onactivitycreated(savedinstancestate); modulo.getoverflowmenu(getactivity()); activitycompat.invalidateoptionsmenu(getactivity()); }
Comments
Post a Comment