You can only put data that can be represented as a String
in a string-array element. However, if you have severals pieces of data you want in each item and they can all be represented as a String
, you can then separate them with a delimiter. Generally I use the pipe symbol |
then you can get the array out of the resources, iterate through them and split on your delimiter to get the separate data again.
Updated with example:
Assuming some XML like this:
<string-array name="menu_items">
<item>/path/to/images/image1.png|First Image</item>
<item>/path/to/images/image2.png|Second Image</item>
<item>/path/to/images/image3.png|Third Image</item>
<item>/path/to/images/image4.png|Fourth Image</item>
</string-array>
You could parse it to get the image and title out like this:
private Map<String, String> parseImageArray {
Map<String, String> imageMap = new Map<String, String>();
String[] imageArray = getResources().getStringArray(R.array.menu_items);
for (String arrayEntry : imageArray) {
String[] keyValue = arrayEntry.split("|");
imageMap.put(keyValue[1], keyValue[0]);
}
return imageMap;
}
Now you have a Map of the image title to image paths