How to disable chips in android

Viewed 2476

I've chip group that I want to disable when some operation happen.

Currently my code look like this:

           R.id.all -> {
                    chipGroup.clearCheck()
                    chipGroup.isClickable = false
                    selectedCategory = null
                } 

It does clear all the checks, but I still can click and select chips.

How can I prevent all the chips from being clicked?

2 Answers

This Kotlin Extension Function allows you to enable/disable all Chips within the Chip Group:

    fun ChipGroup.setChildrenEnabled(enable: Boolean) {
        children.forEach { it.isEnabled = enable }
    }

You can use it like this:

    chipGroup.setChildrenEnabled(false)
public void setChipEnable(boolean status) {
    for (int i = 0; i < chipGrp.getChildCount(); i++) {
        chipGrp.getChildAt(i).setEnabled(status);
    }
}

setChipEnable(false);
Related