I\'m working with a FragmentStatePagerAdapter using this example.
The MyAdapter class is implemented as follows:
public static class MyAdapter extends Fr
I think the solution is much simpler than the answers provided.
If you take a look at the source of FragmentStatePagerAdapter.instantiateItem(), you'll notice that instantiateItem()
handles this logic for you, and thus your implementation of getItem()
should always return a new instance.
So in order to return an existing Fragment, simply do (assuming you're calling from ViewPager
):
Fragment f = (Fragment) getAdapter().instantiateItem(this, getCurrentItem());