Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Disable menu button?

Tags:

android

menu

I have a custom menu options that I want to disable it from popping up if a button on screen is clicked..

I thought of using this code but it doesnt work:

@Override
 public boolean onPrepareOptionsMenu (Menu menu) {
     if (Schedule)
         menu.getItem(1).setVisible(View.GONE);
     return true;
 }

Is there a way to prevent the menu button from doing anything? Thanks.

like image 328
Omar Avatar asked Jul 29 '11 16:07

Omar


1 Answers

According to the documentation:

You must return true for the menu to be displayed; if you return false it will not be shown.

So I'm guessing this will work:

@Override
 public boolean onPrepareOptionsMenu (Menu menu) {
     .... Code .....
     return !Schedule;
 }

That is assuming that you want the menu to display when Schedule is equal to false.

like image 61
DeeV Avatar answered Oct 01 '22 13:10

DeeV