java.lang.IndexOutOfBoundsException: Inconsistency detected. Invalid view holder adapter

java.lang.IndexOutOfBoundsException: Inconsistency detected. Invalid view holder adapter positionViewHolder{25e06b25 position=11 id=-1, oldPos=-1, pLpos:-1 no parent} android.support.v17.leanback.widget.HorizontalGridView{107a60cf VFED… …ID 0,124-1920,194 #7f0a055c app:id/mTitleGroupView}, adapter:com.wasu.launcher.adapter.presenter.TitleAdapter@23f3c0ab, layout:android.support.v17.leanback.widget.GridLayoutManager@2bf5308, context:com.wasu.launcher.MainActivity@1767d1fd
at android.support.v7.widget.RecyclerView R e c y c l e r . v a l i d a t e V i e w H o l d e r F o r O f f s e t P o s i t i o n ( R e c y c l e r V i e w . j a v a : 5610 ) a t a n d r o i d . s u p p o r t . v 7. w i d g e t . R e c y c l e r V i e w Recycler.validateViewHolderForOffsetPosition(RecyclerView.java:5610) at android.support.v7.widget.RecyclerView Recycler.validateViewHolderForOffsetPosition(RecyclerView.java:5610)atandroid.support.v7.widget.RecyclerViewRecycler.tryGetViewHolderForPositionByDeadline(RecyclerView.java:5792)
at android.support.v7.widget.RecyclerView R e c y c l e r . g e t V i e w F o r P o s i t i o n ( R e c y c l e r V i e w . j a v a : 5752 ) a t a n d r o i d . s u p p o r t . v 7. w i d g e t . R e c y c l e r V i e w Recycler.getViewForPosition(RecyclerView.java:5752) at android.support.v7.widget.RecyclerView Recycler.getViewForPosition(RecyclerView.java:5752)atandroid.support.v7.widget.RecyclerViewRecycler.getViewForPosition(RecyclerView.java:5748)
at android.support.v17.leanback.widget.GridLayoutManager.getViewForPosition(GridLayoutManager.java:1085)
at android.support.v17.leanback.widget.GridLayoutManager 2. c r e a t e I t e m ( G r i d L a y o u t M a n a g e r . j a v a : 1624 ) a t a n d r o i d . s u p p o r t . v 17. l e a n b a c k . w i d g e t . S i n g l e R o w . a p p e n d V i s i b l e I t e m s ( S i n g l e R o w . j a v a : 113 ) a t a n d r o i d . s u p p o r t . v 17. l e a n b a c k . w i d g e t . G r i d . a p p e n d V i s i b l e I t e m s ( G r i d . j a v a : 396 ) a t a n d r o i d . s u p p o r t . v 17. l e a n b a c k . w i d g e t . G r i d L a y o u t M a n a g e r . a p p e n d V i s i b l e I t e m s ( G r i d L a y o u t M a n a g e r . j a v a : 1945 ) a t a n d r o i d . s u p p o r t . v 17. l e a n b a c k . w i d g e t . G r i d L a y o u t M a n a g e r . s c r o l l D i r e c t i o n P r i m a r y ( G r i d L a y o u t M a n a g e r . j a v a : 2468 ) a t a n d r o i d . s u p p o r t . v 17. l e a n b a c k . w i d g e t . G r i d L a y o u t M a n a g e r . s c r o l l H o r i z o n t a l l y B y ( G r i d L a y o u t M a n a g e r . j a v a : 2398 ) a t a n d r o i d . s u p p o r t . v 7. w i d g e t . R e c y c l e r V i e w 2.createItem(GridLayoutManager.java:1624) at android.support.v17.leanback.widget.SingleRow.appendVisibleItems(SingleRow.java:113) at android.support.v17.leanback.widget.Grid.appendVisibleItems(Grid.java:396) at android.support.v17.leanback.widget.GridLayoutManager.appendVisibleItems(GridLayoutManager.java:1945) at android.support.v17.leanback.widget.GridLayoutManager.scrollDirectionPrimary(GridLayoutManager.java:2468) at android.support.v17.leanback.widget.GridLayoutManager.scrollHorizontallyBy(GridLayoutManager.java:2398) at android.support.v7.widget.RecyclerView 2.createItem(GridLayoutManager.java:1624)atandroid.support.v17.leanback.widget.SingleRow.appendVisibleItems(SingleRow.java:113)atandroid.support.v17.leanback.widget.Grid.appendVisibleItems(Grid.java:396)atandroid.support.v17.leanback.widget.GridLayoutManager.appendVisibleItems(GridLayoutManager.java:1945)atandroid.support.v17.leanback.widget.GridLayoutManager.scrollDirectionPrimary(GridLayoutManager.java:2468)atandroid.support.v17.leanback.widget.GridLayoutManager.scrollHorizontallyBy(GridLayoutManager.java:2398)atandroid.support.v7.widget.RecyclerViewViewFlinger.run(RecyclerView.java:4956)
at android.view.Choreographer C a l l b a c k R e c o r d . r u n ( C h o r e o g r a p h e r . j a v a : 767 ) a t a n d r o i d . v i e w . C h o r e o g r a p h e r . d o C a l l b a c k s ( C h o r e o g r a p h e r . j a v a : 580 ) a t a n d r o i d . v i e w . C h o r e o g r a p h e r . d o F r a m e ( C h o r e o g r a p h e r . j a v a : 549 ) a t a n d r o i d . v i e w . C h o r e o g r a p h e r CallbackRecord.run(Choreographer.java:767) at android.view.Choreographer.doCallbacks(Choreographer.java:580) at android.view.Choreographer.doFrame(Choreographer.java:549) at android.view.Choreographer CallbackRecord.run(Choreographer.java:767)atandroid.view.Choreographer.doCallbacks(Choreographer.java:580)atandroid.view.Choreographer.doFrame(Choreographer.java:549)atandroid.view.ChoreographerFrameDisplayEventReceiver.run(Choreographer.java:753)
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:5254)
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:906)
at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:701)

异常触发条件

在滑动过程中修改 item 个数,且默认总个数正好处于某个值,例如横向显示的 RecyclerView 一屏正好能显示出来8个item,那么这个列表的总个数要大于或等于12,小于或等于9也没问题,否则就会出现上面异常;

解决方案:

在修改 adapter 数据和 notifyxxx 之前,先执行如下代码,目的是让修改数据前先停止滑动

if (mRecyclerView.getScrollState() == RecyclerView.SCROLL_STATE_SETTLING) {
    mRecyclerView.dispatchTouchEvent(MotionEvent.obtain(SystemClock.uptimeMillis(), SystemClock.uptimeMillis(), MotionEvent.ACTION_CANCEL,0,0,0));
}
  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值