3

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?

Community
  • 1
  • 1
Tony
  • 172
  • 3
  • 11

2 Answers2

5

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 .

Ali Imran
  • 8,927
  • 3
  • 39
  • 50
1

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.

Vincent Mimoun-Prat
  • 28,208
  • 16
  • 81
  • 124
  • 1
    your solution can't solve my problem. because, the Views within viewpager may have dependency Relationship. for example, the Seconde View's content my depend the first view's result which get from web. – Tony Dec 05 '12 at 08:32
  • I am adding youtube video on every viewpager but it wan't work as view pager load next page as well .. so i need only one page to be load – amity May 11 '17 at 12:42