RecyclerView中Adapter的notifyDataSetChanged不生效解决方法

版权声明:本文出自_莫逸的博客,转载必须注明出处。 https://blog.csdn.net/RedWolfChao/article/details/80894861

百度半天解决不了,最后实验半天解决了 但是原因不明

  • 在Adapter中暴露一个setList的方法,传入以改变的数据,然后在setList调用notifyDataSetChanged即可(mDataList是Adapter的数据):
    public void setList(List<String> mDataList) {
        //  如果不行就把下方注释打开
        //  this.mDataList.clear();
        this.mDataList = mDataList;
        notifyDataSetChanged();
    }
  • 确定notifyDataSetChanged调用在主线程(凑数的,并没有什么卵用)

猜你喜欢

转载自blog.csdn.net/RedWolfChao/article/details/80894861