androidandroid-buttontogglebuttonmaterial-components-androidmaterialbutton

How to make all the childs of a Material Button ToggleGroup not clickable in kotlin


i have a lots of child buttons in a toggle group. And i want that whenever one of the child is clicked, make the whole toggle group not clickable.


Solution

  • You can use the OnButtonCheckedListener() listener:

        materialButtonToggleGroup.addOnButtonCheckedListener { group, checkedId, isChecked ->
            for (i in 0 until materialButtonToggleGroup.childCount) {
                materialButtonToggleGroup.getChildAt(i).isClickable = false
            }
        }