I have the following XML
<string-array name="str_arr1">
<item>My item 1</item>
<item>My item 2</item>
<item>My item 3</item>
</string-array>
<string-array name="str_arr2">
<item>My item 4</item>
<item>My item 5</item>
<item>My item 6</item>
</string-array>
How can I reference the above strings arrays using an array.. something like below (maybe another type of array needs to be used?)
<string-array name="my_strings_arrays">
<item>R.array.str_arr1</item>
<item>R.array.str_arr2</item>
</string-array>
Basically in the code, I want to read the my_strings_arrays and then for each array , I want to grab the list of items within.
In any xml resource file we can use reference of array/string/integer/color/etc. with "@" prefix.
So, here we can use @array for getting reference of another array str_arr1 and str_arr2.
<string-array name="str_arr1">
<item>My item 1</item>
<item>My item 2</item>
<item>My item 3</item>
</string-array>
<string-array name="str_arr2">
<item>My item 4</item>
<item>My item 5</item>
<item>My item 6</item>
</string-array>
You to need change your code as below.
<string-array name="my_strings_arrays">
<item>@array/str_arr1</item>
<item>@array/str_arr2</item>
</string-array>
Your second array should be an array of string arrays, not string array of string arrays.
I think the way you would do what you need is:
<array name="my_strings_arrays">
<item>@array/str_arr1 </item>
<item>@array/str_arr2 </item>
</array>
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With