Added View has RecyclerView as parent but view is not a real child. Unfiltered index:0
阿新 • • 發佈:2018-11-12
公司專案列表用的開源專案BaseRecyclerViewAdapterHelper,版本號是2.1.3
測試反饋當快速下滑載入更多時,有時會崩潰,說是歷史遺留問題,所以沒怎麼在意
但今天有一個列表在三星S6上很容易崩潰,日誌如下
java.lang.IllegalStateException: Added View has RecyclerView as parent but view is not a real child. Unfiltered index:0 at android.support.v7.widget.RecyclerView$LayoutManager.addViewInt(RecyclerView.java:7109) at android.support.v7.widget.RecyclerView$LayoutManager.addView(RecyclerView.java:7073) at android.support.v7.widget.RecyclerView$LayoutManager.addView(RecyclerView.java:7061) at android.support.v7.widget.LinearLayoutManager.layoutChunk(LinearLayoutManager.java:1428) at android.support.v7.widget.LinearLayoutManager.fill(LinearLayoutManager.java:1377) at android.support.v7.widget.LinearLayoutManager.scrollBy(LinearLayoutManager.java:1193) at android.support.v7.widget.LinearLayoutManager.scrollVerticallyBy(LinearLayoutManager.java:1043) at android.support.v7.widget.RecyclerView$ViewFlinger.run(RecyclerView.java:4413) at android.view.Choreographer$CallbackRecord.run(Choreographer.java:775) at android.view.Choreographer.doCallbacks(Choreographer.java:588) at android.view.Choreographer.doFrame(Choreographer.java:557) at android.view.Choreographer$FrameDisplayEventReceiver.run(Choreographer.java:761) at android.os.Handler.handleCallback(Handler.java:739) at android.os.Handler.dispatchMessage(Handler.java:95) at android.os.Looper.loop(Looper.java:135) at android.app.ActivityThread.main(ActivityThread.java:5276) at java.lang.reflect.Method.invoke(Native Method) at java.lang.reflect.Method.invoke(Method.java:372) at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:911) at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:706)
開始懷疑是資料問題,因為有些資料很容易崩潰,有些則不會,但並沒有發現數據異常
接著懷疑是addFooter的問題,去掉果然好多了,沒有出現崩潰,但是沒有載入更多提示,體驗非常不好
同事提醒說可能是控制元件的問題,於是Google了一下,還真讓找到了
https://github.com/CymChad/BaseRecyclerViewAdapterHelper/issues/354
升級到2.2.2版本,完美相容,版本ok
貼下修復連結和截圖