TEL:400-8793-956
当前位置:程序、服务器

RecycleView行为异常!“ notifyItemRangeInserted(int positionStart,int itemCount)”方法花费太长时间

提问者: 近期获赞: 浏览人数: 发布时间:2021-01-11 10:30:53

 问:当添加为NestedScollView的子级时,RecyclerView的行为不正常(将新项目添加到RecyclerView中需要花费2分钟以上的时间来反映)

 
 
添加为NestedScollView的子代时,RecyclerView的行为不正确
 
问题-RecyclerView的notifyItemRangeInserted(int positionStart,int itemCount)方法需要花费2分钟以上的时间才能将新的Items视图添加到窗口中。
 
 
 
一种。当positionStart = 0时,它会立即添加项目,但是随着所有项目再次重新绑定到适配器,图像也会再次重新加载。因此,这不是使用positionStart = 0的最佳实践。
 
 
 
b。当positionStart = currentSize + 1时,添加新添加的项目要花费2分钟以上的时间。
 
 
 
预期的行为-应该在几秒钟内添加视图。 
 
 
 
注意-可能正在发生,因为RecyclerView已添加到NestedScrollView中。请研究此问题,因为它限制了开发人员在使用NestedScrollView作为其父视图来实现UI设计时使用此组件。 
 
 
 
代码片段: 
 
 
 
=================================================== =================
 
 if (productList != null && productList.getData().size() > 0) {
                int currentSize = adapter.getItemCount(); // Getting current items Count
                adapter.addToProductsList(productList);  // Adding new items to the existing list
                adapter.notifyItemRangeChanged(currentSize+1, adapter.getItemCount());
=================================================== =================
 
 
答:确保在主线程上通知适配器,如果仍然无法解决,请在此处发布整个代码。
上一篇: 如何对对象的数组列表进行排序?
下一篇: 在决定哪种游戏引擎最适合学习基础方面需要建议