Search code examples
androidandroid-viewpager

Using page adapter without fragments


Is it possible to use ViewPager without fragments? All examples i could find load several fragments to the ViewPager.

I want to use it similarly to a ListView. I would like to create a custom adapter that will inflate a layout according to the position the pager is in.

if it's possible can anyone point me to an example for that ?


Solution

  • Yes its totally possible. Since ViewPager.setAdapter() takes any instance PageAdapter, you just need to create your own subclass of PagerAdapter (its kinda like subclassing BaseAdapter or ArrayAdapter that you use in a ListView). just remember, for PAgerAdapter the docs say:

    When you implement a PagerAdapter, you must override the following methods at minimum:

    Hope this helps