0

This is how I make a static ChipGroup

 <com.google.android.material.chip.ChipGroup
        android:id="@+id/chip_group_filter"
        android:layout_width="match_parent"
        android:layout_height="wrap_content"
        android:layout_below="@id/searchPromo"
        android:layout_marginLeft="10dp"
        android:layout_marginTop="5dp"
        android:layout_marginRight="10dp"
        app:singleSelection="false">

        <com.google.android.material.chip.Chip
            android:id="@+id/chpFoodcourt"
            style="@style/Widget.MaterialComponents.Chip.Filter"
            android:layout_width="wrap_content"
            android:layout_height="wrap_content"
            android:text="Foodcourt"
            android:textColor="#0088BE"
            app:chipStrokeColor="#0088BE"
            app:chipStrokeWidth="1dp" />

        <com.google.android.material.chip.Chip
            android:id="@+id/chpParking"
            style="@style/Widget.MaterialComponents.Chip.Filter"
            android:layout_width="wrap_content"
            android:layout_height="wrap_content"
            android:text="Parking"
            android:textColor="#0088BE"
            app:chipStrokeColor="#0088BE"
            app:chipStrokeWidth="1dp" />

        <com.google.android.material.chip.Chip
            android:id="@+id/chpRestaurant"
            style="@style/Widget.MaterialComponents.Chip.Filter"
            android:layout_width="wrap_content"
            android:layout_height="wrap_content"
            android:text="Restaurant"
            android:textColor="#0088BE"
            app:chipStrokeColor="#0088BE"
            app:chipStrokeWidth="1dp" />

        <com.google.android.material.chip.Chip
            android:id="@+id/chpRetail"
            style="@style/Widget.MaterialComponents.Chip.Filter"
            android:layout_width="wrap_content"
            android:layout_height="wrap_content"
            android:text="Retail"
            android:textColor="#0088BE"
            app:chipStrokeColor="#0088BE"
            app:chipStrokeWidth="1dp" />

        <com.google.android.material.chip.Chip
            android:id="@+id/chpGame"
            style="@style/Widget.MaterialComponents.Chip.Filter"
            android:layout_width="wrap_content"
            android:layout_height="wrap_content"
            android:text="Game"
            android:textColor="#0088BE"
            app:chipStrokeColor="#0088BE"
            app:chipStrokeWidth="1dp" />

        <com.google.android.material.chip.Chip
            android:id="@+id/chpCafe"
            style="@style/Widget.MaterialComponents.Chip.Filter"
            android:layout_width="wrap_content"
            android:layout_height="wrap_content"
            android:text="Cafe"
            android:textColor="#0088BE"
            app:chipStrokeColor="#0088BE"
            app:chipStrokeWidth="1dp" />

        <com.google.android.material.chip.Chip
            android:id="@+id/chpFashion"
            style="@style/Widget.MaterialComponents.Chip.Filter"
            android:layout_width="wrap_content"
            android:layout_height="wrap_content"
            android:text="Fashion"
            android:textColor="#0088BE"
            app:chipStrokeColor="#0088BE"
            app:chipStrokeWidth="1dp" />

        <com.google.android.material.chip.Chip
            android:id="@+id/chpHospital"
            style="@style/Widget.MaterialComponents.Chip.Filter"
            android:layout_width="wrap_content"
            android:layout_height="wrap_content"
            android:text="Hospital"
            android:textColor="#0088BE"
            app:chipStrokeColor="#0088BE"
            app:chipStrokeWidth="1dp" />
    </com.google.android.material.chip.ChipGroup>

enter image description here

Then, instead having hardcoded Chips, I want to fetch the fitch list from API, like this:

 val interestList = arguments?.getStringArrayList("INTEREST_LIST")

 interestList.forEach {
     val theChip = Chip(requireActivity())
     theChip.text = it.toString()
     theChip.isCheckable = true
     theChip.isClickable = true
     theChip.setTextColor(Color.parseColor("#0088BE"))
     //theChip.setTextAppearanceResource(R.style.Widget_Material3_Chip_Filter)

     chipGroupFilter.addView(theChip)
 }

And here's the result. The chip list is fetched correctly, except the rounded rectangle border isn't drawn. enter image description here

Yes, the border only appears after it's clicked, though

enter image description here

How to make the rounder rectangle border always visible?

anta40
  • 6,511
  • 7
  • 46
  • 73

1 Answers1

0

You are defining a style in your XML but there is no style in the code you use to create the Chips programmatically. Take a look at this answer for a way to pass along the style. I prefer the inflation method.

Cheticamp
  • 61,413
  • 10
  • 78
  • 131