java.lang.IllegalArgumentException: Called attach on a child which is not detached: BaseViewHolder{2b241e1 position=12 id=-1, oldPos=-1, pLpos:-1} androidx.recyclerview.widget.RecyclerView{afecb06 VFED..... ......ID 0,0-1080,2055 #7f09236e app:id/recycler_view_xxx}, adapter:com.xxxx.adapter.XxxAdapter@cfc75c7, layout:androidx.recyclerview.widget.LinearLayoutManager@24af7f4, context:com.xxxx.XxxActivity@1ed75e2 at androidx.recyclerview.widget.RecyclerView$5.attachViewToParent(RecyclerView.java:917) at androidx.recyclerview.widget.ChildHelper.attachViewToParent(ChildHelper.java:239) at androidx.recyclerview.widget.RecyclerView.addAnimatingView(RecyclerView.java:1438) at androidx.recyclerview.widget.RecyclerView.animateDisappearance(RecyclerView.java:4377) at androidx.recyclerview.widget.RecyclerView$4.processDisappeared(RecyclerView.java:616) at androidx.recyclerview.widget.ViewInfoStore.process(ViewInfoStore.java:242) at androidx.recyclerview.widget.RecyclerView.dispatchLayoutStep3(RecyclerView.java:4210) at androidx.recyclerview.widget.RecyclerView.dispatchLayout(RecyclerView.java:3864) at androidx.recyclerview.widget.RecyclerView.onLayout(RecyclerView.java:4410) at android.view.View.layout(View.java:22213) at android.view.ViewGroup.layout(ViewGroup.java:6340) at android.widget.RelativeLayout.onLayout(RelativeLayout.java:1131) at android.view.View.layout(View.java:22213) at android.view.ViewGroup.layout(ViewGroup.java:6340) at androidx.viewpager.widget.ViewPager.onLayout(ViewPager.java:1775) at android.view.View.layout(View.java:22213) at android.view.ViewGroup.layout(ViewGroup.java:6340) at android.widget.LinearLayout.setChildFrame(LinearLayout.java:1829) at android.widget.LinearLayout.layoutVertical(LinearLayout.java:1673) at android.widget.LinearLayout.onLayout(LinearLayout.java:1582) at android.view.View.layout(View.java:22213) at android.view.ViewGroup.layout(ViewGroup.java:6340) at android.widget.RelativeLayout.onLayout(RelativeLayout.java:1131) at android.view.View.layout(View.java:22213) at android.view.ViewGroup.layout(ViewGroup.java:6340) at android.widget.FrameLayout.layoutChildren(FrameLayout.java:332) at android.widget.FrameLayout.onLayout(FrameLayout.java:270) at android.view.View.layout(View.java:22213) at android.view.ViewGroup.layout(ViewGroup.java:6340) at android.widget.LinearLayout.setChildFrame(LinearLayout.java:1829) at android.widget.LinearLayout.layoutVertical(LinearLayout.java:1673) at android.widget.LinearLayout.onLayout(LinearLayout.java:1582) at android.view.View.layout(View.java:22213) at android.view.ViewGroup.layout(ViewGroup.java:6340) at android.widget.FrameLayout.layoutChildren(FrameLayout.java:332) at android.widget.FrameLayout.onLayout(FrameLayout.java:270) at android.view.View.layout(View.java:22213) at android.view.ViewGroup.layout(ViewGroup.java:6340) at android.widget.LinearLayout.setChildFrame(LinearLayout.java:1829) at android.widget.LinearLayout.layoutVertical(LinearLayout.java:1673) at android.widget.LinearLayout.onLayout(LinearLayout.java:1582) at android.view.View.layout(View.java:22213) at android.view.ViewGroup.layout(ViewGroup.java:6340) at android.widget.FrameLayout.layoutChildren(FrameLayout.java:332) at android.widget.FrameLayout.onLayout(FrameLayout.java:270) at com.android.internal.policy.DecorView.onLayout(DecorView.java:905) at android.view.View.layout(View.java:22213) at android.view.ViewGroup.layout(ViewGroup.java:6340) at android.view.ViewRootImpl.performLayout(ViewRootImpl.java:3286) at android.view.ViewRootImpl.performTraversals(ViewRootImpl.java:2757) at android.view.ViewRootImpl.doTraversal(ViewRootImpl.java:1865) at android.view.ViewRootImpl$TraversalRunnable.run(ViewRootImpl.java:7933) at android.view.Choreographer$CallbackRecord.run(Choreographer.java:1018) at android.view.Choreographer.doCallbacks(Choreographer.java:837) at android.view.Choreographer.doFrame(Choreographer.java:767) at android.view.Choreographer$FrameDisplayEventReceiver.run(Choreographer.java:1003) at android.os.Handler.handleCallback(Handler.java:883) at android.os.Handler.dispatchMessage(Handler.java:100) at android.os.Looper.loop(Looper.java:230) at android.app.ActivityThread.main(ActivityThread.java:7951) at java.lang.reflect.Method.invoke(Native Method) at com.android.internal.os.RuntimeInit$MethodAndArgsCaller.run(RuntimeInit.java:526) at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:1034)
问题分析
对同一个 position 位置同时进行notifyItemRemoved(position) 和 notifyItemInserted(position) 操作导致。