onPrepareOptionsMenu() for fragments

1,376 views
Skip to first unread message

Alex Fu

unread,
Dec 27, 2011, 6:40:39 PM12/27/11
to ActionBarSherlock
Does anyone know how one would invalidate the options menu for a
Fragment? I have a ListFragment and each row has some text and a
checkbox. Whenever a row is clicked, I'd like to have the options menu
dynamically change. The onPrepareOptionsMenu() doesn't seem to work
for a fragment.

Jake Wharton

unread,
Dec 27, 2011, 6:49:58 PM12/27/11
to actionba...@googlegroups.com

It should be dispatched to fragments as long as your prepare in the activity is returning true.

Alex Fu

unread,
Dec 28, 2011, 10:54:09 PM12/28/11
to ActionBarSherlock
Ah, thanks Jake. This holds true for the normal APIs for Fragments
correct? Not just the compat libs?

On Dec 27, 6:49 pm, Jake Wharton <jakewhar...@gmail.com> wrote:
> It should be dispatched to fragments as long as your prepare in the
> activity is returning true.

Jake Wharton

unread,
Dec 28, 2011, 10:56:45 PM12/28/11
to actionba...@googlegroups.com

Alex Fu

unread,
Dec 28, 2011, 11:19:03 PM12/28/11
to ActionBarSherlock
Yeah, even though I now have my FragmentActivity's
onPrepareOptionsMenu() returning true, the options menu for it's
fragment is not updating unless I "swipe" to a different page and then
"swipe" back (I should of mentioned that I am using ViewPager +
TabHost).

I appreciate the work you've put into ABS.

On Dec 28, 10:56 pm, Jake Wharton <jakewhar...@gmail.com> wrote:
> Hmm... no. I thought I checked this!
>
> https://github.com/android/platform_frameworks_base/blob/master/core/...
>
> Will patch in the dev branch.
>
> ---
> Jake Whartonhttp://about.me/jakewharton

Jake Wharton

unread,
Dec 28, 2011, 11:32:44 PM12/28/11
to actionba...@googlegroups.com
I've had a few people say that but I could never reproduce it. It also seems to happen in the regular compat lib so I'm praying it's not an ABS specific bug. If you can create a test app that will show the error I can try to take a look.

Anyways, the prepare fix is on the dev branch if you'd like to try it.

---
Jake Wharton
http://about.me/jakewharton

Alex Fu

unread,
Dec 28, 2011, 11:39:35 PM12/28/11
to ActionBarSherlock
Once I'm done checking out the dev branch, I'll see if I can send you
a test app with this problem.

On Dec 28, 11:32 pm, Jake Wharton <jakewhar...@gmail.com> wrote:
> I've had a few people say that but I could never reproduce it. It also
> seems to happen in the regular compat lib so I'm praying it's not an ABS
> specific bug. If you can create a test app that will show the error I can
> try to take a look.
>
> Anyways, the prepare fix is on the dev branch if you'd like to try it.
>
> ---

Alex Fu

unread,
Dec 29, 2011, 1:27:19 AM12/29/11
to ActionBarSherlock
That fix you applied on the dev branch worked. Thanks again.
Reply all
Reply to author
Forward
0 new messages