BaseQuickAdapter 增加addfootview view后adddata报错 ViewHolder views must not be attached when created. En

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);
}

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值