I have a chipgroup
and some chips
inside. I loop through this chipgroup
, get every chip
and add a checkedChangeListener
for it.
for (int i = 0; i < chipGroup.getChildCount(); i++) {
final Chip chip = (Chip) chipGroup.getChildAt(i);
chip.setOnCheckedChangeListener((buttonView, isChecked) -> {
//My code
});
}
So when I open my app and click on chip
, e.g. chip1
, it selects it. Then when I click on that chip1
second time, it also fires the checkedChangeListener
and runs my code inside it. The isChecked
status is not helping, because it just changes it value like true->false->true->false
on every click. But I just don't want to run my code inside onCheckedChangeListener
, if the chip is
already checked.
One solution I think is to save my selected chip
inside fragment
or ViewModel
. What's your solution?