Android 解决Recycler View: Inconsistency detected.

Recycler View: Inconsistency detected. Invalid view holder adapter positionViewHolder
这是android的一个已知bug,可以通过try-catch解决,没有副作用

public class WrapContentLinearLayoutManager extends LinearLayoutManager {
    //... constructor
    @Override
    public void onLayoutChildren(RecyclerView.Recycler recycler, RecyclerView.State state) {
        try {
            super.onLayoutChildren(recycler, state);
        } catch (IndexOutOfBoundsException e) {
            Log.e("Error", "IndexOutOfBoundsException in RecyclerView happens");
        }
    }
}

你可能感兴趣的:(Android 解决Recycler View: Inconsistency detected.)