Jul 15, 2021
Good question! I think the solution here is to pass the id of the TaskItem in the listener through to the ViewModel, and then have the ViewModel look up in List<Task> for that id.
in ViewHolder:
itemView.setOnClickListener { onTaskItemClicked(id) }
in ViewModel:
fun onTaskItemClicked(id: Int) {
val task = tasks.first { it.id == id }
// do something
}