android - RecyclerView DiffUtil.dispatchUpdateTo 完成通知
问题描述
我目前正在使用 DiffUtil 类来计算更新并将更新发送到我的适配器ListUpdateCallback
,如下所示:
inner class NotificationCallback(private val onInsert: () -> Unit) : ListUpdateCallback {
override fun onInserted(position: Int, count: Int) {
notifyItemRangeInserted(position, count)
Log.d("NotificationCallback", "onInserted position: $position count: $count")
onInsert()
}
override fun onChanged(position: Int, count: Int, payload: Any?) {
notifyItemRangeChanged(position, count)
Log.d("NotificationCallback", "onChanged position: $position count: $count")
}
override fun onMoved(fromPosition: Int, toPosition: Int) {
notifyItemMoved(fromPosition, toPosition)
Log.d("NotificationCallback", "onMoved from: $fromPosition to: $toPosition")
}
override fun onRemoved(position: Int, count: Int) {
notifyItemRangeRemoved(position, count)
Log.d("NotificationCallback", "onRemoved position: $position count: $count")
}
}
正如您从这段代码中看到的那样,我正在使用相关方法更新适配器,但我只想在插入某些内容时运行一些代码。但是,这确实有效,因为可以(并且)在插入代码之后调用其他通知方法,这会导致插入某些内容时我正在运行的代码出现一些问题。理想情况下,我需要知道所有更新何时已发送到适配器,以便我可以在需要时运行相关代码。有没有这样的方法或方法可以知道这一点?
我目前的解决方案是用来postDelayed
执行这段代码,并希望适配器更新在它运行时已经完成。不漂亮,也不理想!
解决方案
推荐阅读
- javascript - 我在使用 transform-decorators-legacy 时遇到问题
- python-3.x - 如何在python中使用相同的键向字典添加值?
- python - 某些数据未存储在数组中
- netsuite - 计算百分比范围的机会数
- angular - Angular - 保存提交按钮未保存到数据库中
- python - 如何正确定义 Keras 循环层的 input_dim
- css - 将父元素变换为凹形,同时也分别变换其子元素
- python-3.x - 如何删除 DM 中的机器人消息?
- javascript - 如何在我对弹性搜索的一半请求中修复“400 Bad request”?
- html - 我的下拉内容不会显示,但在我移动标题之前它会显示