One approach would be storing the drawables in strings.xml as a string array something like this:
<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>
Then reading this array in your activity code :
TypedArray locationFlags=getResources().obtainTypedArray(R.array.location_flags);
Then applying the for loop you can get the Drawable something like this:
for(int i=0i<locationFlags.length();i++)
{
Drawable drawable = locationFlags.getResourceId(i, -1);
}
Be sure to recycle the TypedArray after using it, since its a shared resource :
locationFlags.recycle();
与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…