In my app I use an array of drawable ids.
It’s an XML file saved at res/values/arrays.xml:
<?xml version="1.0" encoding="utf-8"?>
<resources>
<array name="icons">
<item>@drawable/home</item>
<item>@drawable/settings</item>
<item>@drawable/logout</item>
</array>
</resources>
Then I retrive it using this code:
Resources res = getResources();
TypedArray icons = res.obtainTypedArray(R.array.icons);
Drawable drawable = icons.getDrawable(0);
But I get an error saying: array “cannot be resolved or is not a field”.
So How do I get an array of ints that contains the ids from the xml file?
Thanks 🙂
My code was ok. In my res dir there was an image with a capital letter in it’s name! and that’s Invalid file name which must contain only [a-z0-9_.] 🙂 So that’s why there was an error in the R class. Thanks you guys!