How to get selected chips from ChipGroup?

后端 未结 3 1986
小蘑菇
小蘑菇 2021-01-03 07:43

I search a lot on internet but couldn\'t find the exact solution. Here is the link that i last tried from SO. Get selected Chips from a ChipGroup

I want to get selec

3条回答
  •  执笔经年
    2021-01-03 07:55

    the solution I used in Kotlin with data binding

    mBinding?.chipGroup?.children
                ?.toList()
                ?.filter { (it as Chip).isChecked }
                ?.forEach { //here are your selected chips as 'it' }
    

    And here is how I got just titles

    mBinding?.chipGroup?.children
                ?.toList()
                ?.filter { (it as Chip).isChecked }
                ?.joinToString(", ") { (it as Chip).text }
    

提交回复
热议问题