Mohanish Nerurkar Mohanish Nerurkar - 1 year ago 269
Android Question

How can we implement data binding for Switch button for onCheckedChageListener event?

As question indicates, how to bind checked change listener to Switch button in xml ?

I am not using recycler view. Just a simple layout.

Any help appreciated.

Answer Source

You can do it with a method reference:

<CheckBox android:onCheckedChanged="@{callback::checkedChangedListener}".../>

or with a lambda expression if you want to pass different parameters:

<CheckBox android:onCheckedChanged="@{() -> callback.checked()}".../>
Recommended from our users: Dynamic Network Monitoring from WhatsUp Gold from IPSwitch. Free Download