Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Android: How can I make a Drawable array?

Tags:

android

How can I make an array that handles some of my images so that I can use it like this?:

ImageView.setImageResource(image[1]); 

I hope I explained well...

like image 586
JoeyCK Avatar asked Jul 28 '10 16:07

JoeyCK


People also ask

How do I make my own drawable?

in Drawable folder of res in project directory, make xml file and name it as layerlist. xml and paste it below code as your requirement. you can also add your shape drawable instead of drawable in the <item/> tag in the example. and use this xml as a background of ImageView .


1 Answers

To do that, you don't want an array of Drawable's, just an array of resource identifiers, because 'setImageResource' takes those identifiers. How about this:

int[] myImageList = new int[]{R.drawable.thingOne, R.drawable.thingTwo}; // later... myImageView.setImageResource(myImageList[i]); 

Or for a resizable version:

ArrayList<Integer> myImageList = new ArrayList<>(); myImageList.add(R.drawable.thingOne); // later... myImageView.setImageResource(myImageList.get(i)); 
like image 125
Walter Mundt Avatar answered Sep 28 '22 16:09

Walter Mundt