Databinding: pass null as argument

Viewed 619

How can I pass null as argument via databinding?

when it just

android:onClick="@{() -> viewModel.switchFunction(null)}"

I get cannot find method switchFunction(java.lang.Object) exception.

My ViewModel function is

fun switchFunction(param: MyClass?) {
}
2 Answers

As it turned out, it's preaty easy - just need to specify type of null:

<data>
    <import type="classes.MyClass" />
</data>
...
android:onClick="@{() -> viewModel.switchFunction((MyClass) null)}"
Related