0

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?

sarin
  • 5,227
  • 3
  • 34
  • 63
Krishnan
  • 428
  • 1
  • 4
  • 11

1 Answers1

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