GapWorker with Scrapped or attached views may not be recycled. isScrap:false isAttached:true

后端 未结 3 642
Happy的楠姐
Happy的楠姐 2021-01-18 03:56

When i scroll my recyclerview too fast i am getting the following crash

 java.lang.IllegalArgumentException: Scrapped or attached views may not be recycled.          


        
相关标签:
3条回答
  • 2021-01-18 04:01

    In my case the problem was because of the incorrect implementing of this method public long getItemId(int position) (overrided from RecyclerView.Adapter method).

    The old code will get two different ids for the same item (in my case it is the footer item), after fixing the implementation the issue has gone.

    0 讨论(0)
  • 2021-01-18 04:05

    Have you tried layoutManager.setItemPrefetchEnabled(false);? It worked for me.

    0 讨论(0)
  • 2021-01-18 04:13

    I had the same problem and I don't know why is happening.

    I solved it removing the android:animateLayoutChanges on the recyclerview and to animate the recyclerview I have added: recyclerView.setItemAnimator(new DefaultItemAnimator());

    Take an account to add the method public long getItemId(int position) and set setHasStableIds(true) if you want animate it.

    0 讨论(0)
提交回复
热议问题