Android Options Menu in Fragment -
i trying add item options menu group of fragments.
i have created new menufragment class , extended fragments wish include menu item in. here code:
public class menufragment extends fragment { menuitem fav; @override public void oncreate(bundle savedinstancestate) { super.oncreate(savedinstancestate); sethasoptionsmenu(true); } public void oncreateoptionsmenu(menu menu, menuinflater inflater) { fav = menu.add("add"); fav.seticon(r.drawable.btn_star_big_off); } } for reason oncreateoptionsmenu appears not run.
call super method:
@override public void oncreate(bundle savedinstancestate) { super.oncreate(savedinstancestate); sethasoptionsmenu(true); } @override public void oncreateoptionsmenu(menu menu, menuinflater inflater) { // todo add menu entries here super.oncreateoptionsmenu(menu, inflater); } put log statements in code see if method not being called or if menu not being amended code.
also ensure calling sethasoptionsmenu in oncreate notify fragment should participate in options menu handling.
Comments
Post a Comment