How to add choice chip dynamically in android studio in my case

I have Model Class Like this:

private String animalName, type;

public Model(){}

public Model(String animalName, String type){
 this.animalName = animalName;
 this.type = type;
//and getter and setters for all vars

And ArrayList<Model>(); according to my model class

so I want to check if my ArrayList<>() contains a specific Type ie. herbivore then add those animals according to their type in different ArrayList and I want to make CHOICE CHIPS according to my type. here is an example of my app:

enter image description here

Note I am using RecyclerView to display Images

How Can I add That Choice Chips According to my Model Class and OnClick on any chips load shows Images according to that.

Any Solution is Appreciated.


You can Create A Method name it like this or whatever you want

private void setChips(String type){
    Chip chip = new Chip(this);
    //if you not create chipGroup in you xml yet then create it 

And then you can call that method and pass your type for ie – “Herbivores” etc.


And After that you can add ClickListeners to Your chips like this:

for (int i = 0; i < chipGroup.getChildCount(); i++) {
     int finalI = i;
     chipGroup.getChildAt(i).setOnClickListener(v -> {
            Chip chip = chipGroup.findViewById(chipGroupFl.getChildAt(finalI).getId());

            //here you can call your method to load Images