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.
Asked
Active
Viewed 1,962 times
0

Soheil Setayeshi
- 2,343
- 2
- 31
- 43
2 Answers
3
You can call ViewPager.setOffscreenPageLimit(k)
to cache all entities of ViewPager from n-k to n+k.

Desert
- 2,293
- 15
- 16
-
1Yes but it works only when we load a page once and the first time it only keep n-k not n+k (before first loading ) – Soheil Setayeshi Jul 17 '13 at 09:30
-
Can you show the order in which you setting Adapter to ViewPager and setOffscreenPageLimit? Because as I see from code inside ViewPager it should work. – Desert Jul 17 '13 at 09:38
-
There is only one order in which we initialize the adaper by our custom adapter and then pager.setOffscreenPageLimit(5); for example. – Soheil Setayeshi Jul 17 '13 at 09:44
-
Maybe it is initialized before and the view of the next page will not update fast :-?? any idea how to update the next view?? – Soheil Setayeshi Jul 17 '13 at 09:50
-
just to be sure, did you set large enough OffscreenPageLimit? – Desert Jul 17 '13 at 09:55
-
yes , I th9nk you are right and it is initialized and I need to refresh the incoming view. thx – Soheil Setayeshi Jul 17 '13 at 09:58
1
ViewPager itself handles it.. For instance, if you are currently at item n, the FragmentPagerAdapter calls the onCreateView() of fragments at n-1, n and n+1.

Abhishek Shukla
- 1,242
- 8
- 11
-
2But it work when a page is loaded before and didn't work for new pages. – Soheil Setayeshi Jul 17 '13 at 09:22