1. 程式人生 > >java.lang.IllegalArgumentException: Called attach on a child which is not detached: ViewHolder

java.lang.IllegalArgumentException: Called attach on a child which is not detached: ViewHolder

轉載請標明出處,維權必究:https://www.cnblogs.com/tangZH/p/10116298.html 

在專案過程中出現了上述錯誤。

會出現這樣的錯誤是在我使用:

notifyItemRemoved(position);

notifyItemRangeChanged(position, mList.size() - position);

的時候出現的,其實是因為我的RecycleView有FootView,而當我刪除最後一個Item的時候,notifyItemRangeChanged(position, mList.size() 裡面的position對應的Item就變成FootView了(呼叫notifyItemRemoved(position);並不會重新整理position,可參考:

https://www.cnblogs.com/tangZH/p/10116095.html),由於FootView沒有繫結ViewHolder,所以呼叫notifyItemRangeChanged(position, mList.size() - position)相當於重新整理FootView,出現了該錯誤。