admin 管理员组

文章数量: 1184232

RecyclerView , IllegalStateException: Cannot call this method while RecyclerView is computing a layo

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

在使用recycleview的时候,里面的每一项都有一个seekbar的子控件,当同时滑动几个seekbar的时候就有可能导致app crash掉,报这个错误.原因是我再滑动某个seekbar的时候,其他seekbar也要跟着动态更新.而更新的时候需要用到adapter的notifydatachange,所以我在seekbar的滑动结束之后开放接口出去,让adapter那边更新.就是在同时滑动几个seekbar的时候也触发来 recycleview的滑动事件,这时候就会报recycleview在计算layout或者滑动的时候不能调用notifydatachange的错误


解决方法:

在滑动或者计算layout的时候不刷新数据:
判断是否正在滑动的方法是getScrollState(),如果它等于RecyclerView.SCROLL_STATE_IDLE说明不在滑动,判断有没有在计算layout的方法是isComputingLayout(),取否就可以得到不在计算的时候,通过这两个条件来决定是否刷新数据

本文标签:

Error[2]: Invalid argument supplied for foreach(), File: /www/wwwroot/roclinux.cn/tmp/view_template_quzhiwa_htm_read.htm, Line: 58
File: /www/wwwroot/roclinux.cn/tmp/route_read.php, Line: 205, include(/www/wwwroot/roclinux.cn/tmp/view_template_quzhiwa_htm_read.htm)
File: /www/wwwroot/roclinux.cn/tmp/index.inc.php, Line: 129, include(/www/wwwroot/roclinux.cn/tmp/route_read.php)
File: /www/wwwroot/roclinux.cn/index.php, Line: 29, include(/www/wwwroot/roclinux.cn/tmp/index.inc.php)