android two-way data binding for checkbox using int

105 Views Asked by At

I have a User data class as below and I need to use two-way data binding for the checkbox using the active variable.

  • active == 1, check
  • active == 0, uncheck

data class User( var name: String, var active: Int )

android:checked="@={viewModel.user.active == 1}"

I tried this and two-way data binding does not support this. How can I fix this?

1

There are 1 best solutions below

1
Kamran Khan On

Replace

android:checked="@={viewModel.user.active == 1}

TO

android:checked="@{type == 1? true : false}