Using java for Android development.
I have an array that stores image resources. The image resources are named in numerical order (1.png, 2.png, etc). I would like to use a for loop to create the values in the array instead of declaring each value individually.
What I have tried:
private int[] myArray = {R.drawable.r1, R.drawable.r2, etc};
What I would like to do:
private int[] myArray;
myArray = new int[50]
for (i=0; i<50; i++) {
myArray[i] = R.drawable. + "i"
Well this sort of thing is technically possible, but is prone to certain issues. The R class is dynamically generated. While its moderately predictable, if for some reason your generated values change it could completely break your code. However, if you were to do this it would look like this: