I have defined my chipgroup in my XML and adding chips programtically as below:
chip_group_filter.removeAllViews();
for(FilterModel filterModel : Common.categorySelected.getFilters()){
Chip chip = (Chip) getLayoutInflater().inflate(R.layout.layout_filter_item, null);
chip.setText(new StringBuilder(filterModel.getName()));
chip.setCheckedIconVisible(false);
chip_group_filter.addView(chip);
chip.setChipBackgroundColorResource(R.color.lightGray);
chip.setTextColor(getResources().getColor(android.R.color.black));
chip.setOnCheckedChangeListener(new CompoundButton.OnCheckedChangeListener() {
@Override
public void onCheckedChanged(CompoundButton buttonView, boolean isChecked) {
if (isChecked) {
seeSelectedChip(chip);
serviceListViewModel.loadServicesByFilter(chip.getText().toString());
}
}
});
I want to select first chip as default chip and want to execute checkChangedListener event for the same. How to write that logic?
You can use the the method:
chipGroup.check(id)
. It works with theid
of the chip to select.You can use:
or if you don't have the id