一直认为notifyDataSetChanged  是 用来刷新数据的 当数据发生变化的时候调用notifyDataSetChanged

官方说:通知任何注册的观察者数据发生了改变(Notify any registered observers that the data set has changed) --自己翻译的不保证完全正确。。。。。。

今天有空翻阅下源码

public final void notifyDataSetChanged() {mObservable.notifyChanged();
}

在看看 notifyChanged()方法

public void notifyChanged() {// since onChanged() is implemented by the app, it could do anything, including// removing itself from {@link mObservers} - and that could cause problems if// an iterator is used on the ArrayList {@link mObservers}.// to avoid such problems, just march thru the list in the reverse order.for (int i = mObservers.size() - 1; i >= 0; i--) {mObservers.get(i).onChanged();}
}

这里的mObservers 是一个list

protected final ArrayList<T> mObservers = new ArrayList<T>();

这样看来notifyDataSetChanged 是改变list 的元素

在看下源码的注释

相似的方法

* @see #notifyItemChanged(int)
* @see #notifyItemInserted(int)
* @see #notifyItemRemoved(int)
* @see #notifyItemRangeChanged(int, int)
* @see #notifyItemRangeInserted(int, int)
* @see #notifyItemRangeRemoved(int, int)
/*** Notify any registered observers that the data set has changed.** <p>There are two different classes of data change events, item changes and structural* changes. Item changes are when a single item has its data updated but no positional* changes have occurred. Structural changes are when items are inserted, removed or moved* within the data set.</p>** <p>This event does not specify what about the data set has changed, forcing* any observers to assume that all existing items and structure may no longer be valid.* LayoutManagers will be forced to fully rebind and relayout all visible views.</p>** <p><code>RecyclerView</code> will attempt to synthesize visible structural change events* for adapters that report that they have {@link #hasStableIds() stable IDs} when* this method is used. This can help for the purposes of animation and visual* object persistence but individual item views will still need to be rebound* and relaid out.</p>** <p>If you are writing an adapter it will always be more efficient to use the more* specific change events if you can. Rely on <code>notifyDataSetChanged()</code>* as a last resort.</p>

可以看到官方说 notifyDataSetChanged 的作用

Notify any registered observers that the data set has changed. 通知任何注册的观察者数据发生了改变

RecyclerView Adapter中notifyDataSetChanged 的作用相关推荐

  1. RecyclerView.Adapter notifyDataSetChanged 不起作用

    最近项目里要添加个聊天功能,我们使用的是环信SDK. 如果应用启动,不在聊天界面,接收到消息后就弹出通知栏消息通知用户,点击进入聊天界面. 如果用户已经在聊天界面,就要将接收到的数据添加到adapte ...

  2. RecyclerView.Adapter通用基类

    RecyclerView.Adapter通用基类 一般来说,我们在使用RecyclerView的时候,需要自定义一个Adapter,用来适配RecyclerView和data.这里主要来编写这个Ada ...

  3. java getitemcount_RecyclerView.Adapter中的getItemCount() 返回数组的size是出现异常?

    1.问题描述:RecyclerView.Adapter中的getItemCount() 返回数组的size是出现异常.网络用的是okhttp,数据库框架是litepal,功能是从网络上获取JSON数据 ...

  4. 如何在Adapter中正确的使用Context

    1. 前言 最近我在项目中,发现一个同事写 RecyclerView.Adapter 的时候都习惯定义一个全局的私有 mContext,然后在onCreateViewHolder(parent: Vi ...

  5. kotlin中RecyclerView.Adapter通用适配器

    文章目录 结合databinding,livedata BaseViewHolder BaseAdapter recycleView通用adapter 使用 数据bean ViewModel 绑定it ...

  6. RecyclerView中notifyDataSetChanged刷新总结

    除了adapter.notifyDataSetChanged()这个方法之外,新的Adapter还提供了其他的方法,如下: public final void notifyDataSetChanged ...

  7. android电脑文件列表不刷新,Android 利用RecyclerView.Adapter刷新列表中的单个view问题...

    首先使用RecyclerView的adapter继承:RecyclerView.Adapter public class OrderListAdapter extends RecyclerView.A ...

  8. adapter调用notifyDataSetChanged刷新没有起作用的原因

    listview列表中的数据更新后刷新是使用listview的基础,但是有时候在更新数据之后使用notifyDataSetChanged方法刷新页面的时候就出现了没反应的现象. 原因是adapter会 ...

  9. Android记录15--关于ListView中adapter调用notifyDataSetChanged无效的原因

    Android记录15--关于ListView中adapter调用notifyDataSetChanged无效的原因 2014年1月16日 开发记录 话说这个问题已经困扰我很久了,一直找不到原因,我以 ...

最新文章

  1. MySQL报错解决方案:2013-Lost connection to MySQL server
  2. plc以太网端口号虚拟服务器,plc能像pc那样,一个端口号处理多个连接吗?
  3. php html xml,xml和html之间的区别有哪些
  4. VMWare共享文件
  5. SAP CRM Distribution Chain数据模型
  6. AFNetworking网络请求与图片上传工具(POST)
  7. 复杂推理模型从服务器移植到Web浏览器的理论和实战
  8. python解析html xml最好的模块_Python HTML/XML解析器BeautifulSoup(爬虫解析器)
  9. 多些时间能少写些代码
  10. 儿童电脑学习软件_电脑端英语学习宝藏软件
  11. 微信语音识别及网页获取用户信息
  12. 一文看懂DCDC拓扑原理
  13. 机器朗读发音电脑说话
  14. Android 用代码查看本机保存的Wifi密码
  15. 【商业模式学习感悟】《B站:叛逃二次元和想破开的圈》读后感
  16. 最全SQL数据库语法总结
  17. 一个文本按指定字符分割成多个文本
  18. php CI 微信支付扩展 微信扫码支付 jssdk 支付 退款
  19. Python:在小型项目中使用JSON数据库的利器——TinyDB
  20. unity3d折线图

热门文章

  1. 【Spring】工厂模式解耦
  2. LeetCode简单题之整理字符串
  3. LeetCode简单题之检查两个字符串数组是否相等
  4. MLIR多级中间表示概述
  5. TVM部署和集成Deploy and Integration
  6. 2021年大数据ELK(二十三):Kibana简介
  7. 如何自学php框架,如何学习php框架
  8. python 把集合转成字典的方法
  9. Python 元组的使用
  10. Realm 使用的简单教程