我希望获得“活着”ViewHolders的范围。有我不能解决的问题。
class NotesRvAdapter : RecyclerView.Adapter<NoteDateViewHolder> {
private var lastBindPosition = 0
private var lastUnbindPosition = 10
override fun onBindViewHolder(holder: NoteDateViewHolder, position: Int) {
...
onScopeChanged()
}
fun onScopeChanged() {
var maxPosition = 0
var minPosition = 0
if(lastBindPosition > lastUnbindPosition) {
maxPosition = lastBindPosition
minPosition = lastUnbindPosition
} else {
maxPosition = lastUnbindPosition
minPosition = lastBindPosition
}
scopeListener.onChanged(NotesRequest(maxPosition, minPosition))
}
override fun onViewDetachedFromWindow(holder: NoteDateViewHolder) {
lastUnbindPosition = holder.adapterPosition
super.onViewDetachedFromWindow(holder)
}
}
以随机顺序调用onBindViewHolder(...)
和onViewDetachedFromWindow(...)
。这不是唯一的问题:)
任何获得“活着”位置范围的想法? LayoutManager只能提供第一个/最后一个可见项,而不是“绑定”。