I have a strange UI problem. In brief, I have a ViewPager inside of a Fragment (lets call it 'A'). Up to this point, displaying Fragments inside the ViewPager is no problem.
Problem comes in when I press the back button. The back button pops off Fragment A just fine and returns to the previous Fragment, however during this transition, contents of the ViewPager is completely blanked out.
This is quite evident since I have transition animations. I have no idea why this is happening. It's (seems) pretty clear that it has to do with nested Fragments because this only happens on this particular screen which is the only one with nested Fragments.
Code Snippets
Initial Fragment displays a list of items. We click on one item....
@Override
public void onListItemClick(ListView l, View v, int position, long id) {
FragmentManager fm = getFragmentManager();
Fragment f = fm.findFragmentByTag("some_tag_name");
if(f == null) {
f = SomFragment.newInstance(...);
}
getFragmentManager()
.beginTransaction()
.setCustomAnimations(R.anim.slide_in_right, R.anim.slide_out_left,
R.anim.slide_in_left, R.anim.slide_out_right)
.replace(R.id.frame, f)
.addToBackStack(null)
.commit();
}
Now, a new Fragment appears with a ViewPager. ViewPager is initialized...
@Override
public void onViewCreated(View view, Bundle savedInstanceState) {
mPager = (ViewPager) view.findViewById(R.id.viewpager);
mPagerAdapter = new SomeAdapter(getChildFragmentManager());
mPager.setAdapter(mPagerAdapter);
}
I'm not overriding onBackPressed
in the parent Activity or any other funny business. It's very straightforward.