0

I have a ViewPager with a FragmentPagerAdapter. My customer wants me to switch from ViewPager to list; a vertical list with all the fragments.

There can be a lot of fragments, so adding them all in a ScrollView is out of the question.

Can I somehow do this while still using a FragmentPagerAdapter? Adding fragments to, for example, the views in a recyclerview is not a good idea, I suppose?

What might be a good solution? I'm afraid I will have to stop using fragments for this altogether, but there is a lot of controller code in these fragments.

Frank
  • 12,010
  • 8
  • 61
  • 78
  • 2
    Does this help? http://stackoverflow.com/a/22797619/2413303 – EpicPandaForce Jun 23 '15 at 10:14
  • But that will show screen-size pages. ViewPager needs to know the size of the page before it is rendered I think, if I override getPageWidth(int position) in the adapter, I need to know the size before redering, which I don't know. The pages have different heights and I don't want gaps in between: it should look like a list. – Frank Jun 23 '15 at 10:25
  • Ah. Well that's a shame, because that sounds like a RecyclerView thing. – EpicPandaForce Jun 23 '15 at 10:41
  • Yes, I am afraid it is. – Frank Jun 23 '15 at 11:11

1 Answers1

1

Do not use any fragments on any recycling views like list view, recycler view etc. Fragments are attached to its container, in recycler view container will be changed frequently, as it is getting recycled. It will trouble later.

Better you can change the view pager to vertical scrolling view pager. You can refer link to make it vertical scrolling.

Community
  • 1
  • 1
Anitha Manikandan
  • 1,160
  • 7
  • 19
  • 1
    I agree with the RecyclerView thing here, but unfortunately none of those solutions seem adequate enough for Frank. The solution would require more than just switching the orientation of ViewPager because of the varying heights of the fragments. – Zharf Jun 23 '15 at 12:53
  • Jep, I'll accept this as an answer, I will have to rebuild the whole structure, get rid of the fragments and use a recyclerview instead. – Frank Jun 23 '15 at 15:07