Menu based Android interview questions and answersd
1)
Menu Item is part of the menu.xml file. When we want to add a menu in-out activity we need to method OnCreateOptionMenu(Menu menu). But If you want to add any Menu Item at run time then the system calls your activity’s onPrepareOptionsMenu() method. this method passes currently exist menu object to modify the menu item. Please follow the below code for more detail:
@Override public boolean onPrepareOptionsMenu(Menu menu) { if(Build.VERSION.SDK_INT > 11) { invalidateOptionsMenu(); menu.findItem(R.id.option1).setVisible(false); menu.findItem(R.id.option2).setVisible(true); } return super.onPrepareOptionsMenu(menu);
A
Comments
Post a Comment