you can use reflection.
import field class
import java.lang.reflect.Field;
the code
Field[] Fields = R.drawable.class.getFields();
int[] resArray = new int[Fields.length];
for(int i = 0; i < Fields.length; i++) {
try {
resArray[i] = Fields[i].getInt(null);
} catch (IllegalArgumentException e) {
e.printStackTrace();
}
}
arrays.xml res, :
<?xml version="1.0" encoding="utf-8"?>
<resources>
<string-array name="random_imgs">
<item>@drawable/car_01</item>
<item>@drawable/balloon_random_02</item>
<item>@drawable/dog_03</item>
</string-array>
</resources>
:
TypedArray imgs = getResources().obtainTypedArray(R.array.random_imgs);
imgs.getResourceId(i, -1)
mImgView1.setImageResource(imgs.getResourceId(i, -1));