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. Perjuangan seorang mahasuhu

Pala sampe botak
Kepala cenut ..


"Indonesian Android Community [id-android]" 

2. Bajak Thread

Maaf Om Henry, sebetulnya bukan maksud untuk membajak thread. Cuman sekalian 
ngetest, kalau replay kok email bawaannya kok gak bisa diedit, baik pake email 
bawaan spica maupun pake K-9 mail.
Enaknya pake apa yah? Sedangkan kalo pake gmail bawaan spica, gak bisa tambah 
account lagi, bisanya cuman satu aja. Berkali-kali cuba nambah gak bisa-bisa. 
Maklum niy baru make android.

Thanks  before...

"Indonesian Android Community [id-android]" 

3. ScrollView with EditText - Scrolling in EditText Issue

4. The application has stopped unexpectedly. Please try again.

5. Android Market woes... the press finally catch on

6. WebView Horizontal Scroll Not Working

7. Android Emulator - Eclipse cannot see it