我有已在另一个活动中更新的项目数组列表,当我从活动返回时,我想用全新的 ArrayList() 刷新我的 recyclerview。为了避免滞后,我将此刷新放置到其他可运行线程,并放置 ProgressBar 而不是 RecyclerView。
在新线程中,此方法在适配器 ( recyclerViewAdapter.adapterRefreshFoods()
)中调用
fun adapterRefreshFoods(filteredList: ArrayList<Food>){
if (!filteredList.isEmpty()){
foodList = filteredList
notifyDataSetChanged()
}
}
这导致下面的异常。(当我在 UIThread 中刷新它时效果很好)
java.lang.IllegalStateException: Cannot call this method while RecyclerView is computing a layout or scrolling android.support.v7.widget.RecyclerView