I keep getting java.lang.IllegalArgumentException: Scrapped or attached views may not be recycled. isScrap:false isAttached:true when using Fragment with Re
Ok so I've found were the problem was. In my ViewHolder I had in addition to the layout Views, an ORMlite entity (could've been any object that was not part of the layout). The problem was that the ViewHolder's equals() and hashcode() methods were based on the entity which was null. The reason it was null was because with RecyclerView you don't have access to the data position in onCreateViewHolder(), but only in onBindViewHolder(). The adapter data is a list of ORMlite entities in my case, and I want to bundle the entity inside the holder. (Still have to find a way to do this...)
I was expecting a NullPointerException in this case. I've manage to get a NullPointerException by calling holder.setIsRecyclable(true).
Hope this helps others in need..
Thanks
I saw this happen for me when I used a custom object in the ViewHolder for the Recycler View adapter.
To fix the issue I cleared the custom object which in my case was a timer in the onViewRecycled(ViewHolder holder) for the adapter as below:
public void onViewRecycled(ViewHolder holder) {
if(holder instanceof EntityViewHolder) {
if(((EntityViewHolder)holder).timer != null) {
((EntityViewHolder) holder).timer.cancel();
}
}
super.onViewRecycled(holder);
}
This fixed the bug.