I am beginner in Android, I created three menu lists in the action menu. I am not logined-in in the app, but the logout menu is shown. If logged-in the logout menu is visible and the login invisible. If I press logout, the login menu is visible, and the logout menu invisible, please help me?
Asked
Active
Viewed 234 times
0
-
Do you know what is your requirement but decide what you want exactly and write it clearly so that other can understand – Narendra Kothamire Aug 17 '15 at 09:04
1 Answers
2
@Override
public void onPrepareOptionsMenu(Menu menu) {
super.onPrepareOptionsMenu(menu);
MenuItem item3 = menu.findItem(R.id.ID OF MENU);
item3.setVisible(false);
}
// or
// If you wish to hide ALL menu items, just do:
@Override
public void onAttach(final Activity activity) {
super.onAttach(activity);
setHasOptionsMenu(true);
}
@Override
public void onPrepareOptionsMenu(final Menu menu) {
super.onPrepareOptionsMenu(menu);
menu.clear();//This removes all menu items (no need to know the id of each of them)
}

Jignesh Jain
- 1,518
- 12
- 28
-
am use main activity & login activity where use this code?, i create all list menus in main activity – Krishnan Aug 17 '15 at 09:17
-