android - Trying to hide and show menu items on action bar -
i have looked through questions on stack overflow , can't find solution.
@override public boolean onprepareoptionsmenu(menu menu) { menuinflater inflater = getmenuinflater(); inflater.inflate(r.menu.themenu, menu); menuitem item = menu.finditem(r.id.menu_settings); menuitem item2 = menu.finditem(r.id.menu_save); item.setvisible(isdown); item2.setvisible(isdown); return true; }
this sets menu items visible (item1 , item2). onclick works fine
public void inflatetextarea() { if(isdown == true) { isdown = false; linearlayout tl = (linearlayout)findviewbyid(r.id.content); tl.setvisibility(view.visible); scaleanimation scale = new scaleanimation(1, 1, 0, 1); scale.setfillafter(true); scale.setduration(500); tl.startanimation(scale); } }
then sets isdown boolean false. on stack people onprepareoptionsmenu should fire everytime click not case. able hide 1 menu item on onclick function
@override public boolean onoptionsitemselected(menuitem item) { switch(item.getitemid()) { case r.id.menu_settings: log.v("log:","edit_item pressed"); return true; } }
but have multiple menu items need hide , others want show. how can go this?
its not enough change isdown
variable. have call setvisible()
method every time want change visibility. method more setting boolean value, changing boolean value not do.
after changing isdown
value false, need call invalidateoptionsmenu()
re-launch menu calling onprepareoptionsmenu()
again.
try code making menu items unvisible:
... isdown = false; invalidateoptionsmenu(); ...
Comments
Post a Comment