I created an endless extension FragmentPagerAdapter(there are examples of how to achieve this on this site ). This allows me to iterate over 50 (an arbitrary number) sets of 52 fragments (once a week), thereby giving an endless sense of fragments to the user.
When scrolling / jumping between fragments, causing ViewPager.setCurrentItem, there are two scenarios that I see:
- Jumping only one fragment in any case - everything is in order. This is probably due to the code that specializes this use case in
ViewPager.setCurrentItemInternal(look for a comment starting with words We are doing a jump by more than one page) - By repeating more than one fragment, a new fragment is displayed correctly on the screen only if it
setCurrentItemis called when it is smoothScrollset to true(i.e. setCurrentItem(i, true)); otherwise there will be a blank screen
From what I see, this is probably because it ViewPager.scrollToItemhas the following code in it:
if (smoothScroll) {
smoothScrollTo(destX, 0, velocity);
if (dispatchSelected) {
dispatchOnPageSelected(item);
}
} else {
if (dispatchSelected) {
dispatchOnPageSelected(item);
}
completeScroll(false);
scrollTo(destX, 0);
pageScrolled(destX);
}
This is the moment when I stepped out of the depths. Why if/elsedoes this cause the phenomena that I experience?
source
share