Process Name: 'ysbang.cn'
Thread Name: 'main'
Back traces starts.
java.lang.IllegalStateException: ViewHolder views must not be attached when created. Ensure that you are not passing 'true' to the attachToRoot parameter of LayoutInflater.inflate(..., boolean attachToRoot)
at androidx.recyclerview.widget.RecyclerView$Adapter.createViewHolder(TbsSdkJava:6)
at androidx.recyclerview.widget.RecyclerView$Recycler.tryGetViewHolderForPositionByDeadline(TbsSdkJava:34)
at androidx.recyclerview.widget.RecyclerView$Recycler.getViewForPosition(TbsSdkJava:2)
at androidx.recyclerview.widget.RecyclerView$Recycler.getViewForPosition(TbsSdkJava:1)
at androidx.recyclerview.widget.LinearLayoutManager$LayoutState.next(TbsSdkJava:3)
at androidx.recyclerview.widget.LinearLayoutManager.layoutChunk(TbsSdkJava:1)
at androidx.recyclerview.widget.LinearLayoutManager.fill(TbsSdkJava:9)
at androidx.recyclerview.widget.LinearLayoutManager.onLayoutChildren(TbsSdkJava:65)
at androidx.recyclerview.widget.RecyclerView.dispatchLayoutStep2(TbsSdkJava:12)
at androidx.recyclerview.widget.RecyclerView.dispatchLayout(TbsSdkJava:13)
at androidx.recyclerview.widget.RecyclerView.onLayout(TbsSdkJava:2)
at android.view.View.layout(View.java:21088)
at android.view.ViewGroup.layout(ViewGroup.java:6332)
at android.widget.LinearLayout.setChildFrame(LinearLayout.java:1812)
at android.widget.LinearLayout.layoutVertical(LinearLayout.java:1656)
at android.widget.LinearLayout.onLayout(LinearLayout.java:1565)
at android.view.View.layout(View.java:21088)
at android.view.ViewGroup.layout(ViewGroup.java:6332)
at android.widget.LinearLayout.setChildFrame(LinearLayout.java:1812)
at android.widget.LinearLayout.layoutVertical(LinearLayout.java:1656)
at android.widget.LinearLayout.onLayout(LinearLayout.java:1565)
at android.view.View.layout(View.java:21088)
at android.view.ViewGroup.layout(ViewGroup.java:6332)
at android.widget.RelativeLayout.onLayout(RelativeLayout.java:1083)
at android.view.View.layout(View.java:21088)
at android.view.ViewGroup.layout(ViewGroup.java:6332)
at android.widget.FrameLayout.layoutChildren(FrameLayout.java:323)
at android.widget.FrameLayout.onLayout(FrameLayout.java:261)
at android.view.View.layout(View.java:21088)
at android.view.ViewGroup.layout(ViewGroup.java:6332)
at android.widget.LinearLayout.setChildFrame(LinearLayout.java:1812)
at android.widget.LinearLayout.layoutVertical(LinearLayout.java:1656)
at android.widget.LinearLayout.onLayout(LinearLayout.java:1565)
at android.view.View.layout(View.java:21088)
at android.view.ViewGroup.layout(ViewGroup.java:6332)
at android.widget.FrameLayout.layoutChildren(FrameLayout.java:323)
at android.widget.FrameLayout.onLayout(FrameLayout.java:261)
at com.android.internal.policy.DecorView.onLayout(DecorView.java:1332)
at android.view.View.layout(View.java:21088)
at android.view.ViewGroup.layout(ViewGroup.java:6332)
at android.view.ViewRootImpl.performLayout(ViewRootImpl.java:3018)
at android.view.ViewRootImpl.performTraversals(ViewRootImpl.java:2529)
at android.view.ViewRootImpl.doTraversal(ViewRootImpl.java:1599)
at android.view.ViewRootImpl$TraversalRunnable.run(ViewRootImpl.java:7652)
at android.view.Choreographer$CallbackRecord.run(Choreographer.java:1034)
at android.view.Choreographer.doCallbacks(Choreographer.java:839)
at android.view.Choreographer.doFrame(Choreographer.java:768)
at android.view.Choreographer$FrameDisplayEventReceiver.run(Choreographer.java:1020)
at android.os.Handler.handleCallback(Handler.java:873)
at android.os.Handler.dispatchMessage(Handler.java:99)
at android.os.Looper.loop(Looper.java:224)
at android.app.ActivityThread.main(ActivityThread.java:7096)
at java.lang.reflect.Method.invoke(Native Method)
at com.android.internal.os.RuntimeInit$MethodAndArgsCaller.run(RuntimeInit.java:604)
at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:928)
Back traces ends.
产生原因,设置了adapter的addfootview
分页加载时,刷新第一页前
adapter.getdata.clear(),
adapter.notifyDataSetChanged();
第一页数据返回后
adapter.adddata()
adddata()的compatibilityDataSizeChanged方法问题
解决办法
刷新第一页前不clear数据
等加载数据结束后判断
if (page == 1) {
adapter.replaceData(data);
} else {
adapter.addData(data);
}