Using lambda expression and a Switch
:
public void onCheckedChanged(boolean checked) {
// implementation
}
XML file:
<android.support.v7.widget.SwitchCompat
android:onCheckedChanged="@{(switch, checked) -> item.onCheckedChanged(checked)}"
...
/>
Where item
is the class that implements onCheckedChange
method and is imported to the XML file like this:
<data>
<variable
name="item"
type="yourClass"/>
</data>
与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…