【发布时间】:2015-04-22 12:48:36
【问题描述】:
RecyclerView 库最近添加了新的SortedList 类。假设我有一个回调,它实现了一个可以随时间改变的compare() 方法,即底层的 Comparator 可以被关闭。告诉SortedList 完全利用其数据的最佳方法是什么?
【问题讨论】:
-
如果我必须猜测,
beginBatchedUpdates()、recalculatePositionOfItemAt()(每个项目)和endBatchedUpdates(),但这只是基于 API 的猜测。 -
最坏的情况下,developer.android.com/reference/android/support/v7/widget/util/… 回调具有用于更改元素时的方法,但正确的答案可能是 @CommonsWare 的答案。
-
这不是一个糟糕的开始。但是为每个索引调用 recalculatePositionOfItemAt() 不会完全使用它。索引会发生变化,这会导致某些项目被跳过。
标签: java android android-support-library android-recyclerview kotlin