I am trying to call ViewModel from my activity in a snackbar and since it requires a onClickListener it doesn't let me just do a simple
Snackbar.make(mViewBinding.root, "Note has been deleted", Snackbar.LENGTH_LONG).apply {
setAction("Undo", mViewModel.insertNote(event.data!!))
}
So the solution is to call with a View.OnClickListener but I found a weird solution that I'm trying to understand and I'd like to know if any of you could explain to me this.
Snackbar.make(mViewBinding.root, "Note has been deleted", Snackbar.LENGTH_LONG).apply {
setAction("Undo"){
mViewModel.insertNote(event.data!!)
}
}
Question: Why does setting a "{" works the same way? Is it an anonymous function?