android - Update Menu Item from a Fragment -
i have activity hosts viewpager of fragments pages.
the activity has single menuitem has enabled/disabled depending on actions in fragments.
i have gone callbacks, there way menuitem of parent activity in fragment?
like: getactvity().getactionbar().getmenuitem(0);
quoting docs
if want update
your fragments can contribute menu items activity's options menu (and, consequently, action bar) implementing oncreateoptionsmenu(). in order method receive calls, however, must call sethasoptionsmenu() during oncreate(), indicate fragment add items options menu (otherwise, fragment not receive call oncreateoptionsmenu()).
so have in oncreate
sethasoptionsmenu(true); override oncreateoptionsmenu()
@override public void oncreateoptionsmenu(menu menu, menuinflater inflater) { // todo add menu entries here super.oncreateoptionsmenu(menu, inflater); }
Comments
Post a Comment