Search code examples
androidmaterial-components-androidandroid-chips

Android - Remove all chips from chipgroup


How do I remove all chips from a ChipGroup?

I know I can remove one chip by passing it to the removeView method or one chip by it's index by calling the removeViewAt and passing it's index, but I wanted to remove all views.


Solution

  • You can remove all chips by calling the removeAllViews method:

    val chipGroup = findViewById<ChipGroup>(R.id.chip_group)
    chipGroup.removeAllViews()