I would like to store drawable resources' ID in the form of R.drawable.*
inside an array using an XML values file, and then retrieve the array in my activity.
Any ideas of how to achieve this?
I would like to store drawable resources' ID in the form of R.drawable.*
inside an array using an XML values file, and then retrieve the array in my activity.
Any ideas of how to achieve this?
You can't store arrays in R.drawable as far as I know.
What you can do is create an array in config.xml or strings.xml that maps a path to a drawable resource by using an alias resource.
See if this works, and please let me know if you need any additional help.
You use a typed array in
arrays.xml
file within your/res
folder that looks like this:Then in your activity, access them like so:
In the
value
folder createxml
file name itarrays.xml
add the data to it in this wayThen obtain it to your code this way
Then to use a
Drawable
of these in theimg
TypedArray
for example as anImageView
background
use the following codewhere
index
is theDrawable
index.defaultValue
is a value you give if there is no item at thisindex
For more information about
TypedArray
visit this link http://developer.android.com/reference/android/content/res/TypedArray.htmlYou can use this to create an array of other resources, such as drawables. Note that the array is not required to be homogeneous, so you can create an array of mixed resource types, but you must be aware of what and where the data types are in the array.
And obtain the resources in your activity like this
Enjoy!!!!!