0

I have problem with my recyclerview. I have function that remove item in list. When last item didn't showing, it had work fine. But when last item did showing in the end of screen (list), i got error after excute remove item from list.

This my logcat:

java.lang.IllegalArgumentException: Scrapped or attached views may not be recycled. isScrap:false isAttached:true
at android.support.v7.widget.RecyclerView$Recycler.recycleViewHolderInternal(RecyclerView.java:5778)
at android.support.v7.widget.RecyclerView$Recycler.quickRecycleScrapView(RecyclerView.java:5885)
at android.support.v7.widget.RecyclerView$LayoutManager.removeAndRecycleScrapInt(RecyclerView.java:8547)
at android.support.v7.widget.RecyclerView.dispatchLayoutStep3(RecyclerView.java:3698)
at android.support.v7.widget.RecyclerView.dispatchLayout(RecyclerView.java:3365)
at android.support.v7.widget.RecyclerView.onLayout(RecyclerView.java:3886)
at android.view.View.layout(View.java:15664)
at android.view.ViewGroup.layout(ViewGroup.java:4869)
at android.widget.RelativeLayout.onLayout(RelativeLayout.java:1055)
at android.view.View.layout(View.java:15664)
at android.view.ViewGroup.layout(ViewGroup.java:4869)
at android.widget.FrameLayout.layoutChildren(FrameLayout.java:453)
at android.widget.FrameLayout.onLayout(FrameLayout.java:388)
at android.view.View.layout(View.java:15664)
at android.view.ViewGroup.layout(ViewGroup.java:4869)
at android.widget.LinearLayout.setChildFrame(LinearLayout.java:1677)
at android.widget.LinearLayout.layoutVertical(LinearLayout.java:1531)
at android.widget.LinearLayout.onLayout(LinearLayout.java:1440)
at android.view.View.layout(View.java:15664)
at android.view.ViewGroup.layout(ViewGroup.java:4869)
at android.widget.FrameLayout.layoutChildren(FrameLayout.java:453)
at android.widget.FrameLayout.onLayout(FrameLayout.java:388)
at android.view.View.layout(View.java:15664)
at android.view.ViewGroup.layout(ViewGroup.java:4869)
at android.widget.LinearLayout.setChildFrame(LinearLayout.java:1677)
at android.widget.LinearLayout.layoutVertical(LinearLayout.java:1531)
at android.widget.LinearLayout.onLayout(LinearLayout.java:1440)
at android.view.View.layout(View.java:15664)
at android.view.ViewGroup.layout(ViewGroup.java:4869)
at android.widget.FrameLayout.layoutChildren(FrameLayout.java:453)
at android.widget.FrameLayout.onLayout(FrameLayout.java:388)
at android.view.View.layout(View.java:15664)
at android.view.ViewGroup.layout(ViewGroup.java:4869)
at android.view.ViewRootImpl.performLayout(ViewRootImpl.java:2246)
at android.view.ViewRootImpl.performTraversals(ViewRootImpl.java:1968)
at android.view.ViewRootImpl.doTraversal(ViewRootImpl.java:1200)
at android.view.ViewRootImpl$TraversalRunnable.run(ViewRootImpl.java:6401)
at android.view.Choreographer$CallbackRecord.run(Choreographer.java:803)
at android.view.Choreographer.doCallbacks(Choreographer.java:603)
at android.view.Choreographer.doFrame(Choreographer.java:573)
at android.view.Choreographer$FrameDisplayEventReceiver.run(Choreographer.java:789)
at android.os.Handler.handleCallback(Handler.java:733)
at android.os.Handler.dispatchMessage(Handler.java:95)
at android.os.Looper.loop(Looper.java:157)
at android.app.ActivityThread.main(ActivityThread.java:5335)
at java.lang.reflect.Method.invokeNative(Native Method)
at java.lang.reflect.Method.invoke(Method.java:515)
at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:1265)
at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:1081)
at dalvik.system.NativeStart.main(Native Method)

I remove item like this:

public void delete(Entity entity) {
      entities.remove(entity);
      notifyDataSetChanged();
}

What's wrong here? Have any suggestion for my problem? Thanks!

I think may be the cause of this error is remove item i called from Dispoable of rx thread? When i remove item in my activity it's work fine.

Sinh Phan
  • 1,180
  • 3
  • 16
  • 36

1 Answers1

0

You can use notifyItemRangeChanged or notifyItemChanged method RecyclerView Adapter.

  • I still get this error if don't call `notifyItem...` method. When last item didn't showing, it had work fine. But when last item did showing in the end of screen (list), i got error after excute remove item from list. – Sinh Phan Aug 05 '17 at 14:59