Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to disable chips in android

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?

like image 274
ScrapeW Avatar asked May 19 '20 08:05

ScrapeW


People also ask

What is chip button in Android?

Chips are compact elements that represent an attribute, text, entity, or action. They allow users to enter information, select a choice, filter content, or trigger an action.

What is chip group in Android studio?

A ChipGroup is used to hold multiple Chip s. By default, the chips are reflowed across multiple lines. Set the app:singleLine attribute to constrain the chips to a single horizontal line. If you do so, you'll usually want to wrap this ChipGroup in a HorizontalScrollView .


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)
like image 67
Gnzlt Avatar answered Oct 03 '22 19:10

Gnzlt


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

setChipEnable(false);
like image 30
Nithin B Avatar answered Oct 03 '22 18:10

Nithin B