AndroidDev
AndroidDev

Reputation: 137

android two-way data binding for checkbox using int

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

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?

Upvotes: 0

Views: 182

Answers (1)

Kamran Ahmed Khan
Kamran Ahmed Khan

Reputation: 481

Replace

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

TO

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

Upvotes: 0

Related Questions