java.lang.IndexOutOfBoundsException: Inconsistency detected. Invalid view holder adapter positionViewHolder
今天使用 RecyclerView 的时候报了这个错误,看了一下错误信息和日志,感觉很懵逼,日志没有说明是那一行错了,报的是底层的错误。。。。
解决如下:
public class CustomGridManager extends GridLayoutManager {
public CustomGridManager(Context context, int spanCount) {
super(context, spanCount);
}
@Override
public void onLayoutChildren(RecyclerView.Recycler recycler, RecyclerView.State state) {
try {
super.onLayoutChildren(recycler, state);
} catch (Exception e) {
XLog.e("RecyclerView # " + e.getMessage());
}
}
}
创建一个类,继承自你使用的 manager ,重写 onLayoutChildren 方法,捕获一下异常即可解决。