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.
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 )
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
onBindViewHolder
getting called infinitely ?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)
I've fixed the issue by setting bottom constraint to main RecyclerView
as @Pawel suggested in the comments.