我有一个SortedList,我用它来表示回收器视图中的数据,但是我很难在API调用之间“清除”数据。有什么帮助吗?我现在只是在下面的列表中循环一下:
for(int i = 0; i < mList.size(); i++){
removeItemAt(i);
}这似乎不一致地删除一些项目?
谢谢!)
发布于 2015-04-23 18:59:49
如果您查看源代码,您所做的事情的问题是SortedList在调用removeItemAt索引时更改了removeItemAt的大小。因此,当您的mList.size()循环迭代时,for将发生变化,从而导致结果不一致。
这是一种从回收视图SortedList中删除物品的方法。
public void clear() {
mList.beginBatchedUpdates();
//remove items at index 0 so the remove callback will be batched
while (mList.size() > 0) {
mList.remove(mList.get(0));
}
mList.endBatchedUpdates();
}发布于 2015-11-20 17:33:01
支持库的新版本有一个可以使用的SortedList#clear()方法。
https://stackoverflow.com/questions/29832084
复制相似问题