Search code examples
androidandroid-fragmentsandroid-viewpagerandroid-adapterswipe-gesture

Different layouts in a viewpager


I am trying to do something like the android market to show products from different categories. I have implemented that behavior with this library, and it's all running good.

What I want to do now is to have a list view in the page of the categories, and in each one of the others a grid view. Of course, each one of them will have different sources of data.

How can I achieve that ? Does it have anything to do with adapters?


Solution

  • I think you want extend FragmentPagerAdapter, override getItem, and return the proper Fragment object (or ListFragment) depending on the index/position in the ViewPager.

    In the layout xml for your Activity you should include a ViewPager (<android.support.v4.view.ViewPager>), and in your Activity onCreate use the setAdapter method of ViewPager to assign your FragmentPagerAdapter.