Rename menu item in Android -
i rename menu on click of item. tried following didn't change.
i tried item.settitle("landscape"); or item.settitle("portrait");
declare menu:
@override public boolean oncreateoptionsmenu(menu menu) { menuinflater inflater = getmenuinflater(); inflater.inflate(r.menu.main, menu); return true; }
do on click on menu item:
@override public boolean onoptionsitemselected(menuitem item) { boolean result = true; switch(item.getitemid()) { case r.id.oscillation_mode: { if(getscreenorientation() == 1) { log.e("orientation","abc"+getscreenorientation()); item.settitle("landscape"); setrequestedorientation(activityinfo.screen_orientation_landscape); } else { item.settitle("portrait"); setrequestedorientation(activityinfo.screen_orientation_portrait); } break; }
the text same. default portrait.
when call setrequestedorientation()
activity
destroyed , recreated, changes make in memory objects dropped. should make these changes when menu shown instead
@override public boolean oncreateoptionsmenu(menu menu) { menuinflater inflater = getmenuinflater(); inflater.inflate(r.menu.main, menu); menuitem oscillation = menu.finditem(r.id.oscillation_mode); if (getscreenorientation() == 1){ item.settitle("landscape"); }else{ item.settitle("portrait"); } return true; }
Comments
Post a Comment