I want to set my view holder to not recycle, here's the code:
@Override
public void onBindViewHolder(final ViewHolder viewHolder, final int position) {
viewHolder.setIsRecyclable(false);
}
However, when I see the documentation here:
CodePudding user response:
Not recycling the ViewHolder
just means that specific ViewHolder
will be retained and not overwritten when there is new data to bind, the problem with that is the Adapter
will then need to supply another ViewHolder
to make up for the one it can't reuse.
That is why you need to eventually let it recycle i.e. setIsRecycleable(true)
because it kinda defeats the point of the RecyclerView
if it ends up having to create new views to represent data.
A reason you might want to turn off the recycle is to avoid interruptions, maybe the ViewHolder
is playing an animation, or loading a video. Once its done you could then turn on the recycle, to release the ViewHolder
to make sure it can be used again.
CodePudding user response:
It's better to use Listview in this case. The whole meaning of recyclerview is to recycle the view. Else see this post https://stackoverflow.com/a/36275862/3094367