I’m making an app and I make an Arraylist to store multiple drawables, but for some reason when I try
ArrayList<ImageView> img = new ArrayList<ImageView>();
and I try to store drawables directly from drawable directory
img.add(R.drawable.img1);
It’s asking me to change the data type to integer, I don’t know how to test this code if it will return the Image or not, so can someone verify what does this code do when I try to get a single value from the ArrayList?
2
Answers
ImageView is UI element that is used to display drawables, it is not the drawable itself.
R.drawables are stored ints indeed and they represent references to those actual drawables you have stored. So if you want to have list of drawables you need to change type of list to int.
And to change which drawable is displayed you can call
on UI element in your case ImageView
R.drawable.* returns Int. So you must have to create an ArrayList of integers.
It will work fine.