0

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.

Bitwise DEVS
  • 2,858
  • 4
  • 24
  • 67
  • 1
    Are you referring to this line: `chip.isChecked = true` when you're saying it isn't being triggered? Because you're setting the listener *after* that line. – Henry Twist Apr 25 '21 at 11:54
  • @HenryTwist Oh you are right, why did I forget that. Will check it again. – Bitwise DEVS Apr 25 '21 at 12:29

0 Answers0