当前位置:网站首页>Recyclerview 批量更新View:notifyItemRangeInserted、notifyItemRangeRemoved、notifyItemRangeChanged
Recyclerview 批量更新View:notifyItemRangeInserted、notifyItemRangeRemoved、notifyItemRangeChanged
2022-04-23 06:07:00 【张海龙_China】
如果recyclerview 绑定了数据,假设数据有变化,我们通常是:
notifyDataSetChanged 或者:notifyItemChanged(int position)
但如果数据过多notifyDataSetChanged 肯定会消耗一些性能,如果是一次更新多个notifyItemChanged()不行,这个时候用到recyclerview 有一个批量更新的方法notifyItemRangeChanged();
Recyclerview的局部刷新功能:
从指定位置开始刷新指定个item,notifyItemRangeChanged(int,int);
增、删、改的局部刷新:
增:
notifyItemRangeInserted(int startPosition,int itemcount)
startPosition:起始位置,插入数据的位置。
itemcount:数据个数。
删:
notifyItemRangeRemoved(int startPosition,int itemcount)
参数和“增”是相同的,但有个注意的问题点:
调用此方法后需要进行对后面的所有数据进行调用
notifyItemRangeChanged(startPosition,allCount-startPosition);
不然会出现位置异常。(具体原因后期再研究)
改:
直接用notifyItemRangeChanged(int startPosition,int itemcount);
版权声明
本文为[张海龙_China]所创,转载请带上原文链接,感谢
https://blog.csdn.net/Jason_HD/article/details/123486855
边栏推荐
猜你喜欢
Winter combat camp hands-on combat - MySQL database rapid deployment practice lead mouse cloud Xiaobao
OSS云存储管理实践(体验有礼)
项目,怎么打包
【机器学习】笔记 4、KNN+交叉验证
qs. In the stringify interface, the input parameter is converted into a & connected string (with the application / x-www-form-urlencoded request header)
记录webView显示空白的又一坑
Oracle Job定时任务的使用详解
JVM basics you should know
webView因证书问题显示一片空白
Encapsulate a set of project network request framework from 0
随机推荐
谷歌AdMob广告学习
三种实现ImageView以自身中心为原点旋转的方法
JS function package foreach use return can not jump out of the outer function
mysql和pgsql时间相关操作
qs. In the stringify interface, the input parameter is converted into a & connected string (with the application / x-www-form-urlencoded request header)
pycharm Install packages failed
oracle库恢复数据
Ali vector library Icon tutorial (online, download)
MySQL5.7插入中文数据,报错:`Incorrect string value: ‘\xB8\xDF\xAE\xF9\x80 at row 1`
组件化学习(3)ARouter中的Path和Group注解
oracle计算两日期相差多少秒,分钟,小时,天
【机器学习】笔记 4、KNN+交叉验证
实习做了啥
pg库对姓名进行校验
Apprentissage par composantes
B站用户视频观看记录的存储方案
[SM8150][Pixel4]LCD驱动
Exception record-14
从0开始封装一套项目的网络请求框架
Oracle redo log产生量大的查找思路与案例