Chip Group OnCheckedChangeListener() not triggered

后端 未结 6 895
遥遥无期
遥遥无期 2020-12-10 05:13

I\'m trying to make a recyclerview filter based ChipGroup & Chip

I\'m use fragment on my app, so, the fragment who contain the RecyclerView contain a fr

6条回答
  •  一个人的身影
    2020-12-10 05:46

    It works like this way.

    // com.google.android.material.chip.ChipGroup
    app:singleSelection="true"
    
    // com.google.android.material.chip.Chip (R.layout.chip)
    style="@style/Widget.MaterialComponents.Chip.Choice"
    
    // Inflate instead of NEW instance
    val chip = layoutInflater.inflate(R.layout.chip, chipGroup, false) as Chip
    chip.text = "Text"
    chipGroup.addView(chip)
    
    // setOnCheckedChangeListener
    chipGroup.setOnCheckedChangeListener { group, checkedId ->
        // The same checked chip
        if (checkedId == -1) {
            return@setOnCheckedChangeListener
        }
    
        // TODO
    }
    

提交回复
热议问题