moe_nyc
moe_nyc

Reputation: 307

Multiple views in RecyclerView

I'm working with a recyclerView in my app that has three different layouts for it's rows.

I change the visibility of the different views in the layout for each row depending on the the type of data. For example, if it's a text post I change the visibility of the imageView to invisible and if it's an image post I change the visibility of the textView.

Is this a bad practice? Will this be too much overhead for the app?

Upvotes: 1

Views: 1051

Answers (2)

Dmitry Volynski
Dmitry Volynski

Reputation: 51

Please check this answer.

Main idea - you should implement getItemViewType of appropriate adapter and create layout accordingly with type returned by getItemViewType

Upvotes: 1

Xavier Rubio Jansana
Xavier Rubio Jansana

Reputation: 6583

It's not the best approach. See this: How to create RecyclerView with multiple view type?

There are also libraries in case you need more complex behavior while keeping a clean structure. For example, see Groupie.

Upvotes: 1

Related Questions