I have a little Problem: i have a ViewPager with some Pages and i use the FragmentStatePagerAdapter to handle the data. In portrait i have for example 20 pages for the ViewPager and in landscape i have just 10 pages for the ViewPager. So on a orientation change i create a new Adapter with different Data.
Here a little explanation why: I show one image in portrait and two in landscape but always all in count. If i have 10 pictures to show, i have 10 in portrait and 5 in landscape (always two).
But now i have a strange bug:
When i am in Landscape on index 5 and turn the device, the ViewPager's current page is set to 10. If i turn it back again i am on page 5. If i swipe the ViewPage now to page 10 the methode getItem of the adapter is never called and the ViewPage shows me the one portrait picture and not the two for landscape.
How can this happen? Is there a cache in the adapter or ViewPager? In the onCreate of the Activity everything is new created, the adapter and also the data (just strings with path) for the ViewPager.
So any idea how to fix this really scary "feature"?
Here are some code:
onCreate:
mViewPagerAdapter = new ReaderPageViewAdapter(getSupportFragmentManager(), getBaseContext(), mCurrentDocument.mPages, getResources()
.getConfiguration().orientation);
mPageReader = (ReaderViewPager) findViewById(R.id.pager);
mPageReader.setAdapter(mViewPagerAdapter);
adapter getItem:
public Fragment getItem(final int index) {
final PageInfo pageInfo = mPages.get(index);
final PageFragment pageFragment = (PageFragment) PageFragment
.instantiate(mContext, pageInfo.mClss.getName(), pageInfo.mArgs);
return pageFragment;
}
If you need something more just tell me. Thanks
See Question&Answers more detail:
os 与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…