0

I have the following situation: an Activity that contains a Fragment which has a ViewPager that has Fragments:

                                 -> Childfragment
Activity -> Fragment w ViewPager -> Childfragment
                                 -> Childfragment

I use a FragmentStatePagerAdapter on the ViewPager.

The problem is: I have to switch ON and OFF the ActionBarMenu of the Childfragments, my approach was (in short) the following in my host Fragment:

boolean childsHaveMenu = false; 

public void setChildsHaveMenu(boolean childsHaveMenu) {

    this.childsHaveMenu = childsHaveMenu;
    pagerAdapter.notifyDataSetChanged();
    getActivity().supportInvalidateOptionsMenu();

}

and in my FragmentStatePagerAdapter's getItem() method:

        fragment.setHasOptionsMenu(childsHaveMenu);
        return fragment;

Unfortunately, pagerAdapter.notifyDataSetChanged(); and getActivity().supportInvalidateOptionsMenu(); both don't seem to force the Childfragments to 'update' it's ActionBarMenu, at least not consistently.

My second approach was to send an event to the Exposes with a boolean to tell them of they should show their ActionItems and then hiding or showing them in onCreateOptionsMenu(), but again I can't force the Childfragments to call onCreateOptionsMenu() so the ActionBar updates.

Any ideas on how I could solve this would be highly appreciated :)

4

0 回答 0