4

I need to show either text or images in the screen. The text or images (total 10 for one request) are fetched from my server through HttpClient. when the user swipes to the right and reaches 8th slide I need to get the next set of 10 text or images from the server. Is this possible using ViewPager?

Any examples or pointers would be great.

Naveen
  • 1,020
  • 4
  • 15
  • 37
  • 1
    duplicate of [Infinite Scrolling Image ViewPager](http://stackoverflow.com/questions/13668588/infinite-scrolling-image-viewpager) and http://stackoverflow.com/questions/7766630/changing-viewpager-to-enable-infinite-page-scrolling and http://thehayro.blogspot.com/2012/12/enable-infinite-paging-with-android.html and many other pages found trivially by searching `viewpager infinite` in a search engine. – CommonsWare Jun 05 '13 at 11:06
  • @CommonsWare before posting the question, yes I did a google search.. However most of the resources (even the links that you had mentioned) shows infinite scroll with predefined array length.. The viewpager scrolls infinitely with same set of items. But what I'm looking for is an infinite viewpager on different set of items. Is that possible? – Naveen Jun 05 '13 at 11:23
  • "But what I'm looking for is an infinite viewpager on different set of items" -- no, you are not. The items (pages) are the same. The *content* of the items (pages) differ. To draw an analogy, if you have a `ListView` whose `Adapter` returns `1000000` from `getCount()`, we do not create `1000000` rows, but recycle the existing rows, populating them with new content. – CommonsWare Jun 05 '13 at 11:38
  • If recycle will happen why do we set exact length of the array in `getCount()` method? Is it the right way to just hardcode it as 5 or any number for that matter?? Can we replace the content of the array with a different set if the user reaches last but one item and implement Infinite View pager? will that work?? – Naveen Jun 05 '13 at 11:53

1 Answers1

0

I don't have a specific example of how to do this but the basic method would be to add new pages to the ViewPager's adapter.

You can add a listener when the page changes which checks which page is currently visible against how many pages are in the adapter to work out when you need to load additional pages from the server.

Philio
  • 3,543
  • 1
  • 20
  • 33