David Rawson
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

}

--

--

David Rawson
David Rawson

Written by David Rawson

Doing Android things in New Zealand. Views here do not reflect the views of my employer.

No responses yet