search

Home  >  Q&A  >  body text

android - RecyclerView怎么局部删除一批数据?

我给RecyclerView添加了一个头部,如果使用notifyDataSetChanged会照成头部的刷新,所以我想局部删除一些数据,但是调用notifyItemRangeRemoved方法无效,

if (videoSetting.getVideoPictures() != null && videoSetting.getVideoPictures().size() > 0) {
                cameraPhotoList.clear();
                cameraPhotoList.addAll(videoSetting.getVideoPictures());
                mAdapter.notifyItemRangeChanged(1,cameraPhotoList.size());
            } else {
                int count = cameraPhotoList.size();
                cameraPhotoList.clear();
                mAdapter.notifyItemRangeRemoved(1,count);
                mAdapter.notifyItemRangeRemoved(1,count);
            }

在获取到数据的时候更新数据,数据为空的话清空数据,不知道为什么,我调用两次notifyItemRangeRemoved成功实现了

迷茫迷茫2773 days ago524

reply all(1)I'll reply

  • 高洛峰

    高洛峰2017-04-17 17:51:06

    One of the improvements of RecyclerView compared to ListView is that it supports partial refresh, including insertion, deletion or update

    Maybe there is something wrong with the method called, post the code to take a look

    reply
    0
  • Cancelreply