android - 安卓RecyclerView问题
PHPz
PHPz 2017-04-17 17:55:02
0
4
657

我把RecyclerView搞了个上拉加载更多加载完以后服务器会给我一个list<String>这个list里有20个string然后我在adapter里把这个和原来合并了,那么问题来了notifyItemInserted应该传什么值?传20吗?

PHPz
PHPz

学习是最好的投资!

reply all(4)
Ty80

notifyiteminserted(mcontentlist.size,list.size)//传20

刘奇

The new n pieces of data are inserted into the front of the list
notifyItemRangeInserted(0, n);

迷茫

notifyItemInserted(int position)这个方法是针对单条数据插入更新操作时使用,即在列表某个position插入一条数据,看你想做什么了。我想你需要的是notifyItemRangeInserted(int positionStart, int itemCount)这个方法,即批量添加,比如你之前已经有20条数据了,上拉加载更多新来的20条数据则是notifyItemRangeInserted(20, 20);

Ty80

Assume that the previous data is mLastData; the total length position= mLastData.size();
The newly returned data is mNewData, then all the data is mLastData.addAll(mNewData);
Use the area refresh of Recyclerview, notifyItemRangeChanged(position+1, mLastData.size());

Latest Downloads
More>
Web Effects
Website Source Code
Website Materials
Front End Template
About us Disclaimer Sitemap
php.cn:Public welfare online PHP training,Help PHP learners grow quickly!