Android checkboxes not checked correctly in ViewPager with data binding

I think that it has to do with the way checkbox are animated. So I looked up how to skip the animation, and calling jumpDrawablesToCurrentState on the checkbox after checking it does the trick for me.


I created this Kotlin extension property to deal with the problem (obviously only useful if you are writing Kotlin code, not Java)

/**
 * Set the state of a checkbox skipping animations.
 */

var CheckBox.checked: Boolean
    get() = isChecked
    set(value) {
        if(isChecked != value) {
            isChecked = value
            jumpDrawablesToCurrentState()
        }
    }

Now in my code I write checkbox_view.checked = true instead of checkbox_view.isChecked = true

Tags:

Android