I have a list objects in a Recyclerview
. When long-pressing an item I want to show a dialog with data from the item clicked.
The Recyclerview
The hint from Bayoudh led me in the right direction, but I'm posting this to put the pieces together. Below is a cardview that is clickable. Since my ViewModel
holds no reference to the activity we have to pass the view in question as a parameter.
The android:onClick="@{(view) -> viewModel.onClick(view)}"
statement takes the current view as a parameter so you can use it in the ViewModel to get context with view.getContext()
as Bayoudh states.