Spot the bug
After toggling a favourite, the row doesn't update. Which line causes it?
private val items = mutableListOf<Item>()fun toggle(id: Long) {val i = items.indexOfFirst { it.id == id }items[i] = items[i].copy(favourite = !items[i].favourite)adapter.submitList(items)}
Hint 1 of 1
Is the submitted list a new object?
Choose an answer, then open Show answer below to check it.
Show answer
- Answer: line 6
adapter.submitList(items)
The same list instance is submitted again, so ListAdapter sees the same reference and skips the diff. Submit a new list (items.toList(), or currentList.map { ... }).