Bear
Bear

Reputation: 5152

Updating option menu item which is currently showing

Because of some reasons, some menu item is disabled and will be enabled after the data is arrived.
Here is the case that I conern:
When the menu is current showing to user and the data is arrived, how can I enable the menu item instantly?

Now I only enable/disable menu item in onPrepareOptionsMenu(), it is only called when menu is shown again. FYI, I am using android 2.x SDK

Thank You

Upvotes: 0

Views: 144

Answers (2)

Bharat Sharma
Bharat Sharma

Reputation: 3966

I have already done this and it is working fine. Take a look at this code...

While creating your menu add different group to each of your menu option so that you can easily handle each button seperately. like : I am giving you example of hold and resume button. One time only one button will work so how to do that here is code.

Declare this in your class.

private static final int HOLD_CALL      = 0;
private static final int RESUME_CALL    = 1;

Write this code in your public boolean onCreateOptionsMenu(Menu menu)

menu.add(0, HOLD_CALL, 0, "Hold Call");
menu.add(1, RESUME_CALL, 1, "Resume Call");

Use this in your public boolean onMenuOpened(int featureId, Menu menu)

menu.setGroupEnabled(1, false);`

the above code will disable your menu option. Hope it will help you If still you are facing problem then let me know i will try to help you...

Upvotes: 0

h0m3r16
h0m3r16

Reputation: 303

When the opPrepareOptionsMenu is called, it gets a reference to the Menu, so you can save this reference in a Variable, and when the data is ready add or enable de option again.

Upvotes: 1

Related Questions