Reputation: 12639
I have a RecyclerView
whose items must be grouped in CardView
s. There are a variable number of items that will be grouped in each CardView
and the item ViewType
s differ as well. I am struggling with how I can add items to each CardView
such that it grows based on the number of items.
I have attempted using nested RecyclerView
s but this has proved buggy.
All help is greatly appreciated. Thank you.
Upvotes: 0
Views: 314
Reputation: 12639
I have attempted using nested
RecyclerView
s but this has proved buggy.
My implementation is what was buggy. The solution I settled on was to use nested RecyclerView
s. A top level RecyclerView
that would hold the CardView
s and a RecyclerView
in each CardView
to display the variable number of items.
The reason my original implementation was "buggy" was because if the nested RecyclerView
had no items to display, I set the Visibility
to GONE
. This was a poor attempt at optimization. This would cause issues where an item would dynamically be added to the nested RecyclerView
but it wouldn't appear because the nest RecyclerView
was set to GONE
.
If you are using nested RecyclerView
s, in your onBindViewHolder()
method in the Adapter
for the top level RecyclerView
, be sure to update the items in the adapter of the nested RecyclerView
or else it will contain recycled data meant for a different position.
Upvotes: 1