My use case:
I have an activity with a ViewPager
as its only view element, set up with three Fragment
s for its three pages (using a FragmentPagerAdapter
). One of these fragments is a ListFragment
, while the other two regular Fragment
s containing some infographics.
The list in the ListFragment
allows "checking" elements, and checking elements brings up the contextual action bar, presenting a list of actions possible on the selected/checked items.
My problem:
When I select a couple of list items, the CAB shows up. But when I switch pages, the CAB stays visible, presenting the actions. To make matters worse, the ViewPager
seems to sometimes destroy the view of the list fragment - hence selecting the actions throws a "java.lang.IllegalStateException: Content view not yet created"
exception.
My questions:
- How do I get the CAB to disappear when the user moves away from the
ListFragment
page? - (optional) How do I get the CAB to reappear when the
ListFragment
back is and some items are still checked.