2

How to set viewpager load only one page and setOffscreenPageLimit() android

I want to load viewpager load only one page in one time and I want to disable reload page when this page is visible(loaded).

yes, I know if want to load only one page is use viewPager.setOffscreenPageLimit(1);

but I dont know to set disable reload page when this page is visible(loaded).

Example

my app have 3 page in viewpager (page1,Page2,Page3)

when app start -> page 1 is loading

and when i click tab 2(never opened) -> page 2 is loading

and when i click tab 3(never opened) -> page 3 is loading

and when I swipe to page2, page1 (opened) is not reload

How to set it? thanks!

ARR.s
  • 769
  • 4
  • 20
  • 39

1 Answers1

3

viewPager.setOffscreenPageLimit(1) is the default setting without you doing anything to it. 1 stands for the number of pages that should be retained to either side of the current page, i.e. if you are on page n, the ViewPager will load page n -1 and page n + 1. Using the default ViewPager, there is no way to set the offscreen page limit to 0 nor get the wanted behaviour otherwise (while you are able to swipe). See this post.

kalabalik
  • 3,792
  • 2
  • 21
  • 50