Called attach on a child which is not detached

Posted 小林爱

tags:

篇首语:本文由小常识网(cha138.com)小编为大家整理,主要介绍了Called attach on a child which is not detached相关的知识,希望对你有一定的参考价值。

当你的 adapter 添加了headview,adapter.notifyDataSetChanged()就会报Called attach on a child which is not detached

解决办法是如果你添加了headView,那么notifyItemChanges 的index+1

所以adapter.notifyDataSetChanged()替换成adapter.getAdapter().notifyItemChanged(index + 1)

代码如下

var layoutManager = recyclerView.layoutManager as LinearLayoutManager;
var mLastVisibleItemPosition = layoutManager.findLastVisibleItemPosition();
var mFirstVisibleItemPosition = layoutManager.findFirstVisibleItemPosition();
for(index in mFirstVisibleItemPosition..mLastVisibleItemPosition)
    if(headView!=null) 
        adapter.getAdapter().notifyItemChanged(index + 1);
    else
        adapter.getAdapter().notifyItemChanged(index);
    

以上是关于Called attach on a child which is not detached的主要内容,如果未能解决你的问题,请参考以下文章

Called attach on a child which is not detached

Called attach on a child which is not detached

WebView.destroy() called while still attached 的解决的方法

Android - A WebView method was called on thread 'JavaBridge

webView.loadUrl 错误:A WebView method was called on thread 'JavaBridge'.

Androidjava.lang.RuntimeException: java.lang.Throwable: A WebView method was called on thread '