ViewPager + recycling views?

user291701 picture user291701 · Jun 29, 2012 · Viewed 7.7k times · Source

I'd like to create a gallery of photos that swipe left and right. At first I took a look at Gallery, but it's marked as deprecated.

http://developer.android.com/reference/android/widget/Gallery.html

We're told to try ViewPager instead. But the PagerAdapter class doesn't handle recycling of views for us (like a standard ListView), does it?

http://developer.android.com/reference/android/support/v4/view/PagerAdapter.html

Is it up to us to build the recycling mechanism?

Thanks

Answer

josephus picture josephus · Jun 29, 2012

But the PagerAdapter class doesn't handle recycling of views for us (like a standard ListView), does it?

No, and I think it's because it was built assuming you are using different layouts for each of the page.

Also, as it is not being scrolled as fast as a ListView (you cannot "fling" a ViewPager to skip multiple pages), I think it doesn't need to have to recycle.