Cannot find method for data binding event using lambda
the signature of the method has to be the same in the viewModel,
I was using
android:onClick="@{v -> viewModel.settingsClick()}"
and the method in the viewModel was
public void settingsClick() {
...
}
Apparently the data binding generated classes were in a bad state and weren't getting properly regenerated, invalidating caches and cleaning fixed the problem.
As you noted in your comment about the android:onClick="@{vm::doIt}"
solution, your onClick handler must have a View
parameter, even if you don't use it.
Your workaround of calling your parameter-less buttonClicked
method via a lambda will work nicely, so long as the lambda accepts the View
parameter. This is easy. Unused parameters to lambdas can be named "_" for clarity. So your onClick handler can be configured thus:
android:onClick="@{_ -> vm.buttonClicked()}"