Let's make this real simple. I've two model classes, Category
and Movie
.
data class Category(
val id: Long,
val name: String,
val movies: List<Movie>
)
data class Movie(
val name : String
)
Each category has multiple movies. So to render this data, I am using nested RecyclerView
s.
- The problem
When I turn the device to landscape mode, the onBindViewHolder
of MoviesAdapter
(nested recyclerview's adapter) getting called infinitely. (Note, the same code works perfectly fine in portrait mode )
- What I tried
I've changed the layout_width
of nested recyclerview's item to 200dp
from 120dp
, and that's fixed the infinite call in a device, but on a larger screen I had put higher value to fix it.
I know this not an ideal solution, so I tried 'wrap_content` but it didn't work either. (same infinite call issue)
Questions
- Why the
onBindViewHolder
getting called infinitely ? - What's the perfect way to fix this issue ?
- Why the
As I don't want to flood the question feed with the code, I've hosted the reproducible version here (code minimized for the sake of readability)