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. Installing the ADT Plugin

In this section:
Now modify your Eclipse preferences to point to the Android SDK

   1. Select Window > Preferences... to open the Preferences panel
(Mac OS X: Eclipse > Preferences).
   2. Select Android from the left panel.
   3. For the SDK Location in the main panel, click Browse... and
locate your downloaded SDK directory.
   4. Click Apply, then OK.

What does "locate your downloaded SDK directory" refer to?  I can't
find the directory or file on my PC that the Eclipse interface is
referring to...



2. urgent help needed for Home Screen Customization problem

Hi all,

Cant I have my desired content on the HomeScreen of the android?
I want to add some button or any other view.
Only widgets are possible or is there any help related to this.
please give some inputs.



3. How to change File permission

4. Power Down

5. How to play a media file on emulator

6. Listview Text Filter Slow

7. How to get raw video frames?