Issue
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>
Solution
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));
Answered By - Prince Dholakiya
0 comments:
Post a Comment
Note: Only a member of this blog may post a comment.