Resource arrays

19,490

If I understand your question correctly, I think I know a workaround (since accessing them via getResources().getIntArray() doesn't work). (You can read more here, that is the source I took the workaround from.)

TypedArray ar = context.getResources().obtainTypedArray(R.array.my_array);
int len = ar.length();     
int[] resIds = new int[len];     
for (int i = 0; i < len; i++)     
    resIds[i] = ar.getResourceId(i, 0);

ar.recycle();                       
// Do stuff with resolved reference array, resIds[]...     
for (int i = 0; i < len; i++)     
    Log.v (TAG, "Res Id " + i + " is " + Integer.toHexString(resIds[i]));
Share:
19,490
user940016
Author by

user940016

Updated on June 06, 2022

Comments

  • user940016
    user940016 almost 2 years

    Is there a way to define an array in XML in which the elements are resource references? For example (it doesn't work, but it explains what I want):

    <integer-array name="actions_images">
        <item>@drawable/pencil</item>
        <item>@drawable/pencil</item>
        <item>@drawable/pencil</item>
        <item>@drawable/pencil</item>
        <item>@drawable/pencil</item>
        <item>@drawable/pencil</item>
    </integer-array>