I have a ViewPager with 10+ views. I wish to change the order of the pages occasionally i.e.
Page 1 | Page 2 | page 3
to
Page 3 | Page 1 | Page 2
For the tabs I am using ViewPagerIndicator, I am able to update the order of these by changing the order of my adapter and calling:
mViewPagerIndicator.notifyDataSetChanged();
However, what I cannot update is the content of the ViewPager, for example if I update the ViewPager adapter (to the new order I wish the pages to be in) and call:
mViewPager.getAdapter().notifyDataSetChanged()
This has no effect. The tab indicator bar is updated fine but the content of the page still shows the old order.
Is there a way to change the order of pages in a ViewPager adapter and get the ViewPager to reload all it's views?
My ViewPager adapter extends FragmentStatePagerAdapter
and my overridden methods are as follows:
@Override
public Fragment getItem(int position) {
return MyCustomFragment.newInstance();
}
@Override
public void destroyItem(ViewGroup container, int position, Object object) {
//super.destroyItem(container, position, object); // Commented out to ensure views are not destroyed
}
Thanks