En fremgangsmåde ville være at gemme de drawables i strings.xml som en string-array noget som dette:
<string-array name="location_flags">
<item>@drawable/ic_image_name</item>
<item>@drawable/ic_image_name</item>
<item>@drawable/ic_image_name</item>
<item>@drawable/ic_image_name</item>
<item>@drawable/ic_image_name</item>
<item>@drawable/ic_image_name</item>
<item>@drawable/ic_image_name</item>
</string-array>
Læs derefter dette array i din aktivitetskode :
TypedArray locationFlags=getResources().obtainTypedArray(R.array.location_flags);
Ved at anvende for-løkken kan du få Drawable noget som dette:
for(int i=0i<locationFlags.length();i++)
{
Drawable drawable = locationFlags.getResourceId(i, -1);
}
Sørg for at genbruge TypedArray'et efter at have brugt det, da det er en delt ressource :
locationFlags.recycle();