所以我更新我RecylerView
的StateFlow<List>
如下:
我的数据类:
data class Student(val name: String, var isSelected: Boolean)
我的 ViewModel 逻辑:
fun updateStudentsOnSelectionChanged(targetStudent: Student) {
val targetIndex = _students.value.indexOf(targetStudent)
val isSelected = !targetStudent.isSelected
_students.value[targetIndex].isSelected = isSelected //<- doesn't work
}
问题: UI没变,但是isSelected
里面_student
变了,怎么回事?(与 相同LiveData
)