Skip to content Skip to sidebar Skip to footer

Android Viewpager Only Load One Page One Time

ViewPager.setOffscreenPageLimit(0) doesn't work as expected Like the question. But I need a custom Viewpager which load one page on time. Is there any example?

Solution 1:

Yes you can do this with following steps

  • First create a count variable in the adapter class
  • second in the ViewPager Adapter make a public function say setCount()
  • and in the override getCount() function of Adapter return the count variable
  • now override the on pageScroll() function of the ViewPager when the user flips the page you can call the setCount() to increase the count of the count variable
  • also check that if that the current index is last and page is scrolled to left

this should work .

Solution 2:

Depending on what you want to achieve (if it is just about saving memory or lowering loading time), you can also load all pages as usual but load the content of the fragment only when it actually gets displayed.

Post a Comment for "Android Viewpager Only Load One Page One Time"