I have a very big recyclerView in my code with a lot of if statements in the onBindViewHolder: sometimes position 1 to 5 will have this view, sometimes they will have another view, and some other times, they will have another views. I have more than 20 positions in some cases and some positions have sometimes 3 variants.
Can I create a class for each specific variant and then write something like
override fun onBindViewHolder(holder: RecyclerView.ViewHolder, position: Int) {
if (variant 1) {
Variant1Class.onBindViewHolder(holder, position)
}
else if (variant 2) {
variant2Class.onBindViewHolder(holder, position)
}
else {
variant3Class.onBindViewHolder(holder, position
}
}
This way I can split the logic in more than one file. Is it problematic to pass the "holder" variable around ? Is it problematic for some other reason ?
If you have another solution, I'm all ears!
Best