Dynamically enable menu items

by sam » Wed, 02 Sep 2009 17:12:52 GMT

Sponsored Links
 Hi guys,

I would like to know how to dynamically change the my option menu
items status from disable to enabled .

at first all my menu items are set to disabled and when click the menu
key , they are shown as gray and disabled.

when my other task finished, i want to enable all the menu items,
change them from gray to dark color from the screen.

do you know how can i implement this?



Dynamically enable menu items

by Mark Murphy » Wed, 02 Sep 2009 18:24:47 GMT

 > I would like to know how to dynamically change the my option menu

Implement onPrepareOptionMenu() instead of onCreateOptionMenu().
onPrepareOptionMenu() is called every time the MENU button is pressed. At
that time, you know whether your menu items should be enabled/disabled, so
enable/disable them as part of loading up the menu contents.

Mark Murphy (a Commons Guy)
Android App Developer Books:  http://commonsware.com/books.html 


Sponsored Links

Dynamically enable menu items

by sam » Thu, 03 Sep 2009 09:52:38 GMT

 Hi Mark,

Thank for reply.
let me describe my question in more details,
I do not want to press the Menu button again, when the menu items are
displayed as disabled, after I finished some work , i want the menu
items to be repainted automatically.
Any suggestions?



Dynamically enable menu items

by sam » Mon, 07 Sep 2009 12:42:53 GMT

 Hi guys,

Any help on this? I believe android application like browser implement
does the android engineer from google have any comments?



Dynamically enable menu items

by Nivek » Mon, 07 Sep 2009 16:51:28 GMT

 As Menu Items are generated only once in the onCreateOptionsMenu(),
you might try to keep a reference to each item in instance variables
and enable/disable them in the handlers that receive task results ?



Dynamically enable menu items

by Keean Schupke » Mon, 07 Sep 2009 18:09:29 GMT

 Actually you can use:


which is called just before the menu is displayed to add or remove



Dynamically enable menu items

by sam » Tue, 08 Sep 2009 09:15:04 GMT

 HI guys,

Thanks for your replies, i want to change the menu item status from
disable to enabled while it is displaying on the screen.
i can enable it but the menu item does not re-paint themselves when
they are on the screen.

any other comments?




Dynamically enable menu items

by Mark Murphy » Tue, 08 Sep 2009 09:39:20 GMT


If you are trying to say you want the user to click the MENU choice, sit
there for several minutes without touching anything and without the
screen powering off, then something happens in the background and causes
the menu to change...that is *really* esoteric. You can try holding onto
the Menu object and making changes to it, but I doubt that will work.

That does not surprise me. Using hierarchyviewer, it appears that the
menu is not even part of the activity's window, but rather its own
separate window. The menu data probably gets passed to this window only
when the menu opens, not if you change the menu while open.

You are welcome to implement your own menu system that enables this
capability. You are not reliant upon Android's. Just use animations to
slide up a panel, and render your own menu choices, when the user clicks
the MENU button (which you trap via onKeyDown()).

Otherwise, I would focus on the menu working like an ordinary menu, and
move onto more important things.

Mark Murphy (a Commons Guy)
 http://commonsware.com  |  http://twitter.com/commonsguy 

Android Development Wiki:  http://wiki.andmob.org 


Other Threads

1. Query Google Maps

Hi Everyone,

I'd like to make an app that requires access to all (or many) search
results of a maps query.

For example, given the query


the app would have the names/locations of the 49 results.

Does anyone have any ideas on how to do this?


2. Rotate Image

Hi All

I have this problem when rotate the image, every time that this same image
is rotated, the dimensions from the image is changed and are reduced.
existe some way for solution this problem ????

        Bitmap bitmapOrg = imageView.getDrawingCache();

        int width = bitmapOrg.getWidth();
        int height = bitmapOrg.getHeight();

        float scaleWidth = ((float) width) / width;
        float scaleHeight = ((float) height) / height;

         Matrix matrix = new Matrix();
         Bitmap resizedBitmap =  Bitmap.createBitmap(bitmapOrg, 0, 0, width,
height, matrix, true);
         BitmapDrawable bmd = new BitmapDrawable(resizedBitmap);



3. Calendar Widget

4. Investigating for a WebOS style app switcher

5. How to update the AlertDialog

6. MapsActivity has leaked window

7. Android Maps API - TOS/GPS incompatability?