The question is published on by Tutorial Guruji team.
As I described in the answer of this my post GridView animated HORIZONTAL sliding I have a custom calendar made of ViewPager and GridViews on each of 3 views of the ViewPager.
I’ve created an “universal” InfinitePagerAdapter extends PagerAdapter. And my CalendarPagerAdapter extends this InfinitePagerAdapter.
I have adapters for each of the 3 GridViews (One on each page of the 3 ViewPager pages)
Currently I have the following strange effect:
- I slide right and left (by finger) with and everything is fine: The page I slide to (prev/next) is inflated and I see the it just fine during the slide.
- In some undefined moment the sliding looks like this: The page I slide to (prev/next) is not inflated and I see white page during sliding. When the sliding is finished the page is inflated just fine.
Firstable I thought my “pages trick” in the InfiniteViewPagerAdapter is not fast enough for example if slide “too fast” several pages etc.
But the same effect I have if I just put buttons “prev”/”next” and scroll ViewPager by code: ViewPager.setCurrentItem(position, true); Each Slide after this command has the described strange effect (not inflated page). I’ve tried to “force” invalidate all pages on each slide etc. but nothing by now.
I found an easy solution that is good enough for my task:
In the begining right after setting the adapter I set current item to Integer.MAX_VALUE/2
pager.setAdapter(adapter); pager.setCurrentItem(Integer.MAX_VALUE / 2);
I’ve dropped the idea of reusing the view of the 3 pages kept in memory, so I just 1. Create view in instantiateItem(…) and add it to container:
view = inflateView(.....) container.add(view)
2. Remove it from container in destroyItem(…) container.remove(view)