CymChad / BaseRecyclerViewAdapterHelper

BRVAH:Powerful and flexible RecyclerAdapter
http://www.recyclerview.org/
MIT License
24.3k stars 5.15k forks source link

你也因为【Called attach on a child which is not detached: BaseViewHolder】崩溃了吗? #3721

Closed longxuewei closed 1 year ago

longxuewei commented 1 year ago

如果你也遇到了这个问题,那大概是刷新Adapter的时候没有加上 Adapter 的 Header 数量 以及 EmptyView 数量。所以出现这种情况只需要像这样:

mAdapter.notifyItemRangeChanged(positionStart + mAdapter.headerLayoutCount + if (mAdapter.hasEmptyView()) 1 else 0, itemCount)

mAdapter.notifyItemRangeInserted(positionStart + mAdapter.headerLayoutCount + if (mAdapter.hasEmptyView()) 1 else 0, itemCount)

mAdapter.notifyItemRangeRemoved(positionStart + mAdapter.headerLayoutCount + if (mAdapter.hasEmptyView()) 1 else 0, itemCount)