I'm dynamically adding Views to my items in a RecyclerView
. These added Views should only be related to the item which they're added to, but I'm having a problem when I scroll. It seems the View
is recycled and a new item is loaded, but those previously added views are still there, only now on the wrong item.
I'm assuming that it's just because the ViewHolder
is being reused, so the added items show up again with a new item, when loaded.
How would one go about solving this?
You should take any Empty Layout like
Linearlayout
in your child item layoutXML
and then add views into thatLinearLayout
of your particular item in this way when you scroll List all of you child views which you have added toLinearLayout
also scroll with that item .Based on this:
Basically, as per the RecyclerView documentation, You have to reset the views everytime inside the
onBindViewHolder()
method,so let say, you have a method that sets a view param if its your profile, so the code for the same goes as follows,
So what you're doing here is giving recycled ViewHolder a chance to reset. Do comment if you need help!