Inconsistency detected in RecyclerView, How to change contents of RecyclerView while scrolling

前端 未结 26 2523
借酒劲吻你
借酒劲吻你 2020-12-01 00:59

I\'m using RecyclerView to display name of the items. My row contains single TextView. Item names are stored in List mItemList<

26条回答
  •  甜味超标
    2020-12-01 01:42

    I was facing same issue, java.lang.IndexOutOfBoundsException: Inconsistency detected.

    Create Custom LinearLayoutManager.

    HPLinearLayoutManager.java

    public class HPLinearLayoutManager extends LinearLayoutManager {
    
        public HPLinearLayoutManager(Context context) {
            super(context);
        }
    
        public HPLinearLayoutManager(Context context, int orientation, boolean reverseLayout) {
            super(context, orientation, reverseLayout);
        }
    
        public HPLinearLayoutManager(Context context, AttributeSet attrs, int defStyleAttr, int defStyleRes) {
            super(context, attrs, defStyleAttr, defStyleRes);
        }
    
        /**
         * Magic here
         */
        @Override
        public boolean supportsPredictiveItemAnimations() {
            return false;
        }
    }
    

    create instance of HPLinearLayoutManager.

    HPLinearLayoutManager hpLinearLayoutManager = new HPLinearLayoutManager(mContext);
    recyclerView.setLayoutManager(hpLinearLayoutManager);
    

    Hope this would help you.

提交回复
热议问题