我有以下功能:
override fun insertUpdatedItems(items: List<AutomobileEntity>) {
if (!items.isEmpty()) {
items.forEachIndexed { index, automobileEntity ->
if (automobileEntity.id == items[index].id) {
automobileCollection[index] = items[index]
notifyItemInserted(index)
}
}
}
}
我正在使用为 recyclerview 提供数据,我正在尝试插入已更新/编辑的项目,这些项目的automobileCollection大小总是返回10项目,但items列表可能会有所1不同10。
它应该比较项目,id但我目前使用此功能得到的是已编辑的项目只是插入到 recyclerview 的适配器中,而不是被视为已经存在的项目。
相反,如果我使用迭代,automobileCollection我会得到 IndexOutOfBoundsException,因为大多数时候items列表小于automobileCollection.