This is class that extends ToggleButton

class TagGarden : ToggleButton {


    constructor(context: Context?) : this(context, null)
    constructor(context: Context?, attrs: AttributeSet?) : this(context, attrs, 0)
    constructor(context: Context?, attrs: AttributeSet?, defStyleAttr: Int) : this(context, attrs, defStyleAttr, 0)
    constructor(context: Context?, attrs: AttributeSet?, defStyleAttr: Int, defStyleRes: Int) : super(
        context,
        attrs,
        defStyleAttr,
        defStyleRes
    ) {
// empty constructor
}

This is my XML

<in.abc.life.TagGarden
    android:id="@+id/tag"
    android:layout_width="wrap_content"
    android:textOff="OFF"
    android:textOn="ON" 
    android:layout_height="wrap_content"/>

in activity

tag.setOnCheckedChangeListener{ a, b -> {
            Toast.makeText([email protected],"$b checked", Toast.LENGTH_SHORT).show()
}}

OnCheckedChangeListener is not working but when OnClickListener is used toggle starts working but OnCheckedChangeListener still does not work

0 Answers