edd*_*rdo 10 android android-listview android-recyclerview
我正在使用RecyclerView,我在第一个项目之前添加项目,滚动位置向上移动到新添加的第一个项目.如何在第一个索引添加新项目并调用后保持我的滚动位置notifydatasetchange()?
这就是我在我的适配器中所做的
mCurrentFragment.items.addAll(0, createLineItems(dataArrayList));
notifyDataSetChanged();
Run Code Online (Sandbox Code Playgroud)
有什么建议 ?
Bud*_*ius 20
有两种选择:
使用更复杂的版本 notify
List newData = createLineItems(dataArrayList);
mCurrentFragment.items.addAll(0, newData);
notifyItemRangeInserted(0, newData.size());
Run Code Online (Sandbox Code Playgroud)使用稳定的ID.在适配器覆盖上public long getItemId (int position),使其返回MEANINGFUL值并调用setHasStableIds(true);它.
| 归档时间: |
|
| 查看次数: |
7371 次 |
| 最近记录: |