Search code examples
androidandroid-viewpagerfragmentstatepageradapter

Load content of ViewPager before paging


How can I load next page content of a ViewPager before paging. Imagine I'm using a ViewPager to display a book and each page is a fragment which is added to the ViewPager and I want the fragment being loaded before paging the book and user didn't feel the lag while paging the book page.


Solution

  • You can call ViewPager.setOffscreenPageLimit(k) to cache all entities of ViewPager from n-k to n+k.