I am creating a Chips
at runtime to populate ChipGroup
that is in single selection mode, I am programmatically also set check state to true on a first inflation but I noticed that chipGroup.setOnCheckedChangeListener
is never return a callback unless I select new chip item. Is this intended behavior or a bug?
for (i in 0 until categoryChannelList.length()) {
val chip = Chip(context)
chip.id = i
chip.isCheckable = true
//Styling chip codes......
// If no chip is selected, first chip will be set
if (i == 0) {
chip.isChecked = true
}
chipGroup.addView(chip)
}
// Responds to chip newly check
chipGroup.setOnCheckedChangeListener { chipGroup: ChipGroup, checkedId: Int ->
val channelId = chipGroup.findViewById<Chip>(checkedId).tag.toString()
Toast.makeText(requireContext(), channelId, Toast.LENGTH_LONG).show()
}
Usually when listening to check state the behavior would be like a CheckBox onCheckChange
but here it is not the case.