Search code examples
androidandroid-databinding

CheckBox onCheckedListener not working DataBinding


Im trying to listen when the checkbox is checked or not.

Problem

onCheckedListener is never called

What have i tried

XML

<CheckBox
   android:onCheckedChanged="@{(v, checked) -> handler.onCheckedChanged(checked)}"
   ...
 />

<variable
    name="handler"
    type="com.example.tiago.demo.Search.Adapter.Adapter"/>

Adapter.java (com.example.tiago.demo.Search.Adapter)

public void onCheckedChanged(boolean isCheck){
    Log.d("adapter","Is checked: ".concat(String.valueOf(isCheck)));
}

I read similar posts about this on forums and in here, but none of them work for me, this one is the only one that lets me compile with no problems, but when i click on the checkbox i don't get any log message.

Notes

  • i get an error in this line android:onCheckedChanged unknown attribute (all the examples that i see use onCheckedChanged not sure why im getting this message)
  • onCheckedChanged color is yellow the only place i call this is from xml

Solution

  • I was able to fix my issue, i was not binding the variable silly mistake