当前位置: 代码迷 >> 综合 >> IllegalStateException: Cannot call this method while RecyclerView is computing a layout or scrolling
  详细解决方案

IllegalStateException: Cannot call this method while RecyclerView is computing a layout or scrolling

热度:10   发布时间:2023-12-16 22:36:52.0

我是做了个顶部是tabLayout,然后点击每一item,底部的EasyRecyclerView(一个封装了Recyclerview的FrameLayout布局)要对应刷新。

看到报错,发现是不能在滑动或者在计算layout的时候刷新数据

解决方法如下:(getRecyclerView()方法是这个控件封装的,返回的是一个recyclerview对象;如果你是用recyclerview写的就不用调用这个方法,直接调用isComputingLayout()方法和getScrollState()方法即可)

 if (!mRlRoute.getRecyclerView().isComputingLayout() && mRlRoute.getRecyclerView().getScrollState() == RecyclerView.SCROLL_STATE_IDLE) {// 不在滑动或者不在计算layout的时候刷新数据mCustomRouteAdapter.notifyDataSetChanged();}

 

  相关解决方案