I have an infinitely scrolling ViewPager. To accomplish this, I have 5 items (0,1,2,3,4). When at rest, I am always at tab 2. After onPageScrollStateChanged returns to SCROLL_STATE_IDLE, I update the data source to put the current item in position 2 and then I set the ViewPager's current item to 2, like so:
@Override
public void onPageScrollStateChanged(int state) {
if (state == ViewPager.SCROLL_STATE_IDLE) {
populateForecastFragmentsArray();
mPager.setCurrentItem(CENTER_PAGE_INDEX, false);
}
}
This works great to get the infinite scrolling I'm looking for, however, the PagerTabStrip flickers every time setCurrentItem()
is called.
Is there another way to set the current item without using setCurrentItem? Is there a better way to handle infinite scrolling?
I have determined that the flickering happens during setCurrentItem, not populateForecastFragmentsArray(), but just to be complete, here is the code from populateForecastFragmentsArray():
public void populateForecastFragmentsArray () {
mForecastFragmentArrayList.clear();
for (int i = 0; i < mPageAdapter.getCount(); i++) {
ForecastFragment fragment = new ForecastFragment();
int offset = i - CENTER_PAGE_INDEX;
fragment.calendar = (Calendar)mDisplayedDate.clone();
fragment.calendar.add(Calendar.DAY_OF_YEAR, offset);
mForecastFragmentArrayList.add(fragment);
}
}