How get selected chips text in a chip group
Rohit Jakhar
Posted on April 14, 2021
While using chip, sometimes you need selecting multiple chip in a chip group.
After that it is very tedious task to get their text in easy way.
I found a way and i am sharing with you
In this code i selected chips inside Alert Dialog
val builder = AlertDialog.Builder(requireContext())
builder.setTitle("Filter")
val mView = FilterOptionLayoutBinding.inflate(layoutInflater)
builder.setView(mView.root)
builder.setPositiveButton(android.R.string.ok) { d, p ->
mView.chipGroup.checkedChipIds.forEach {
val chip = mView.root.findViewById<Chip>(it).text.toString()
checkedChipsText.add(chip)
}
d.dismiss()
}
builder.setNegativeButton(android.R.string.cancel) { d, _ ->
d.cancel()
}
builder.create()
builder.show()
💖 💪 🙅 🚩
Rohit Jakhar
Posted on April 14, 2021
Join Our Newsletter. No Spam, Only the good stuff.
Sign up to receive the latest update from our blog.