Mikhail
Mikhail

Reputation: 3305

Android. Using fragments in RecyclerView is it right or wrong?

I have a card which addition to other information can contain an image, image slider (third-party library), or video (YouTubeAPI). Earlier I used to card layout, all three media elements (image, slider, video) and, depending on the needs, modify their visibility, hiding unnecessary elements, leaving visible only the necessary.

Then I decided to try to use the fragments. Did the three fragments, for each item (note that the fragments of a class contain all the logic element, he should just pass parameters to initialize, and the rest he will do himself), and tried to use it in RecyclerView. Earlier in my card had three elements, but now I just wanted to put me right fragment in a special container in the card.

I also read that the use of fragments in RecyclerView is a bad practice. Question - is worth in this case the use of fragments, for the sake of simplicity (these fragments are also used in other Activiti and now all logic of the media elements moved to their classes of fragments). Or I must use an old scheme - the card directly contains all the media items that I dynamically made visible/invisible and filled as needed?

enter image description here

Upvotes: 2

Views: 1409

Answers (1)

apelsoczi
apelsoczi

Reputation: 1122

I'm not absolutely clear what your requirement is to modify the views. Each fragment within RecyclerView is a ViewHolder.

This may be worth reading:

Heterogenous Layouts inside RecyclerView

  • RecyclerView is capable of being aware of more than one type of ViewHolder

Upvotes: 1

Related Questions