### 简介 Notify any registered observers that the data set has changed. 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. 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. RecyclerView will attempt to synthesize visible structural change events for adapters that report that they have 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. If you are writing an adapter it will always be more efficient to use the more specific change events if you can. Rely on notifyDataSetChanged() as a last resort. ### 使用notifyDataSetChanged()实现上拉加载 接上篇:[XRecyclerView的简单使用 - TKUONG's BLOGS](http://www.tkuong.cn/index.php/archives/17/) 1.在adapter中添加addData()方法 ~~~kotlin fun addData( data1 : List){ data.addAll(data1) notifyDataSetChanged() } ~~~ 2.在loadmore()方法中调用addData ~~~kotlin //获取完成要添加的数据后调用 adapter.addData( response.resultData.data) ~~~ 在调用完addData()方法后,RecyclerView会将数据自动添加到列表末尾 最后修改:2022 年 05 月 27 日 © 允许规范转载 打赏 赞赏作者 支付宝微信 赞 0 如果觉得我的文章对你有用,请随意赞赏