ListAdapter not refreshing RecyclerView if I submit the same list with different item order

后端 未结 5 1782
挽巷
挽巷 2021-01-12 06:57

I am using a RecyclerView with ListAdapter (which uses AsyncListDiffer to calculate and animate changes when list is replaced).

The problem is that if I

5条回答
  •  抹茶落季
    2021-01-12 07:35

    To add to Carson's answer, which is a better way to do it, you can maintain the benefits of submitList as follows in Kotlin:

    submitList(oldList.toList().toMutableList().let {
         it[index] = it[index].copy(property = newvalue) // To update a property on an item
         it.add(newItem) // To add a new item
         it.removeAt[index] // To remove an item
         // and so on....
         it
    })
    

提交回复
热议问题