I was able to find a solution with significant help on this issue .
- My data is stored in an XML array.
- This data contains an array index that points to an array of images supported under a normal resource.
My data storage file looks like this:
<storage_type> <image imageArrayIndex="1" /> <name>Item_Name1</name> </storage_type> <storage_type> <image imageArrayIndex="2" /> <name>Item_Name2</name> </storage_type>
I have a file in my res / values folder that looks like this:
<resources> <string-array name="images"> <item>@drawable/default</item> <item>@drawable/image1</item> <item>@drawable/image2</item> </string-array> </resources>
And somewhere deep in parsing the XML I have:
TypedArray imgs = context.getResources().obtainTypedArray(R.array.achievement_images); //Whole bunch of code to parse XML, eventually coming to this line: else if (name.equals("image")) { imageRes=imgs.getResourceId(xpp.getAttributeIntValue(null,"imageArrayIndex", 0),-1); }
Alternatively, I could just save the image name as shown below:
<storage_type> <image resid="image1" /> <name>Item_Name1</name> </storage_type> <storage_type> <image resid="image2" /> <name>Item_Name2</name> </storage_type>
And then get it by parsing the XML tag and getting the resource identifier:
int resid=Context.getResources().getIdentifier (name_string_Image, "drawable", null);
source share