I'm trying to create an app where I need to load a bunch of images, and display one after another by tapping on a simple button. But instead of manually typing every ResourceID of an image file into an array:
int imageIDs = {
R.drawable.img1,
R.drawable.img2,
R.drawable.img3,
R.drawable.img4,
R.drawable.img5,
R.drawable.img6,
R.drawable.img7,
R.drawable.img8,
R.drawable.img9,
..
}
I would like to just create a for loop to do the job. I'd assume this should work:
int numberOfImages = 19;
ArrayList<Integer> imageIDs = new ArrayList<Integer>();
for (int i = 0; i <= numberOfImages; i++) {
imageIDs.add(<<resourceIDs*>>);
}
// * Don't know how to state it. R.drawable.img + i does not work.
But that doesn't seem to work. I've tried so many different approaches I found online now, sitting on it for hours, but I did not find anything that worked. Is it even possible to create an array or arrayList with the R.drawable. identifier by looping, or do I have to type it all in manually?
Is there any way to include hundreds of images within my app in Android Studio, without having to type them all in manually?