Back with another one. Trying to get what little app I have to cooperate with 3.0+ Android versions, and have something i’m not sure how to handle..
I have an options menu, which I upgraded to better suit the Action bar, defined as:
<?xml version="1.0" encoding="utf-8"?>
<menu xmlns:android="http://schemas.android.com/apk/res/android">
<item android:titleCondensed="@string/menu_sheet_photo_comp" android:title="@string/menu_sheet_photo" android:id="@+id/mnuCamera" android:icon="@android:drawable/ic_menu_camera" android:showAsAction="ifRoom" />
<item android:titleCondensed="@string/menu_sheet_notes_comp" android:title="@string/menu_sheet_notes" android:id="@+id/mnuLogText" android:icon="@drawable/ic_menu_compose" />
<item android:titleCondensed="@string/menu_sheet_track_comp" android:title="@string/menu_sheet_track" android:id="@+id/mnuTrack" android:icon="@android:drawable/ic_menu_compass" />
<item android:titleCondensed="@string/menu_sheet_geocache_comp" android:title="@string/menu_sheet_geocache" android:id="@+id/mnuGC" android:icon="@drawable/ic_menu_emoticons" android:showAsAction="ifRoom" />
This all works fine as is – when the activity is run, the photo (first one) is displayed on the action bar on my phone, none of othe others are. Now, the options availability depend on a few things.
So, at the beginning of the Activity launch, a thread is sent off to get web data. And onCreateOptionsMenu() I disable the first item. (They cannot take a photo of it until we get web data back verifying it can be photographed.)
On previous versions of my app, it was easy – on onPrepareOptionsMenu() I check the status, and then enable or disable the options, as appropriate. Now, here’s what I can’t figure out how to do –
Since the camera button’s on the action bar, and not in the overflow menu, when the user taps it, onPrepareOptionsMenu() is never called, so the button stays disabled.
So how would I be able to make that button enabled once my background thread returns and I know that I can enable it?
Cheers –
Mike.
Either call invalidateOptionsMenu() and add a check in onCreateOptionsMenu() for the enabling/disabling or create the menus programmatically and hold the Menu instance somewhere, so you can enable it later.