Home » Android » android – ViewPager inside ListView

android – ViewPager inside ListView

Posted by: admin June 15, 2020 Leave a comment


Is there a way to add a viewpager as a listview item?

I want to add it as a “header” on top of my listview before all real list items follow. I tried using addHeaderView() or declaring multiple view types in my list adapter, however, the viewpager never shows up whatever way I try.

Has anyone done something similar? Help!

How to&Answers:

Quoting Dianne Hackborn, ViewPager is “just not intended to be used as an item in a list”


Do not use wrap_content, try to calculate and set ViewPager size programmatically and then add ViewPager as a header of ListView.