I get my data through an API that supplies me with an array of strings for my RecyclerView. Inside each of these lines there is an array of elements that I want to dynamically add to each of the RecyclerView lines. Each item corresponds to a view. So, for example, I can get the title, then the image, then the text. Or I can only get the image. Or title and text. These are just a few of the elements; there are more and perhaps hundreds of different possible combinations. For this reason, it is not practical to create and inflate different types of lines, as usual, if you need only a few different types of lines.
I tried to inflate and bind my views to the line of the onBindViewHolder method, but this caused the elements to be added again and again every time this method is called.
I searched around and did not find similar questions to what I needed, and I was wondering if there is a good clean and elegant way to achieve what I need.
source share