2

I created a string-array in my strings.xml file and I want access array in my layout to fill my chips. How can I do it?

This my strings.xml

<string-array name="shortcutCategoryNames">
    <item>Digital</item>
    <item>Clothes</item>
    <item>Sport</item>
    <item>Cosmetics</item>
</string-array>

This is my layout

        <com.google.android.material.chip.ChipGroup
            android:layout_width="match_parent"
            android:layout_height="wrap_content">
            <com.google.android.material.chip.Chip
                android:id="@+id/chp_digital"
                android:layout_width="wrap_content"
                android:layout_height="wrap_content"
         />
            <com.google.android.material.chip.Chip
                android:id="@+id/chp_clothes"
                android:layout_width="wrap_content"
                android:layout_height="wrap_content"
                />

         <!-- rest of Chips-->

        </com.google.android.material.chip.ChipGroup>
1
  • 2
    "I want access array in my layout to fill my chips" -- there is no mechanism for doing that, sorry. You will need to use Java/Kotlin code to create your chips and put them in the group. Commented Mar 26, 2019 at 10:50

2 Answers 2

2

You can get String Array using below method.

ArrayList<String> tagList = new ArrayList();

String[] someArray = getResources().getStringArray(R.array.shortcutCategoryNames);
tagList.addAll(Arrays.asList(someArray));
Sign up to request clarification or add additional context in comments.

Comments

1

You can get string-array using this code:

String strArray[] = getResources().getStringArray(R.array. shortcutCategoryNames);

Then loop through strArray to create Chip and add those Chip to ChipGroup programmatically

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.