我想給RecyclerView動態的add一個頭view,但是報出了這樣的錯誤。
解決方案
I found the source of this problem. Within RecyclerView.dispatchLayoutStep3(), there's a for loop, "for (int i = 0; i < count; ++i)", where count is based on mChildHelper.getChildCount(). While this iteration is occurring, the collection managed by ChildHelper is modified by ChildHelper.hideViewInternal(), which results in null being returned from the call to mChildHelper.getChildAt() on line 3050 of RecyclerView, which in turn results in null being returned from getChildViewHolderInt() on the same line of code (RecyclerView:3050).
Here's the chain of method calls that results in the modification that breaks the integrity of the for loop:
dispatchLayoutStep3() -> animateChange() -> addAnimatingView() -> hide() -> hideViewInternal()
When ChildHelper adds the child param to its mHiddenViews collection, it violates the integrity of the for loop way up in dispatchLayoutStep3().
I see two workarounds for this:
1>Disable change animation in your RecyclerView
2>Downgrade to 23.1.1, where this wasn't a problem
看到這就有點懵比了,但是項目需求就是一個列表,索性直接拿ListView來替換RecyclerView.