简体   繁体   中英

How to set image to ImageView from ArrayList<String> in android?

I am creating an android application for image sharing.In mainactivity one gridview that shows images from Arraylist<String> named img .when i clicked on any image then another activity called that have only one ImageView that shows image that i select on mainactivity, but i am not able set image in ImageView using ImageView.setImageResource(img.get(currentImage)) method.where img is ArrayList of string type.

any help will be appreciate.

You can create an ArrayList of Integers and then easily assign the image to the imageview:

Example code:

ArrayList<Integer> list = new ArrayList<Integer>();
list.add(R.drawable.your_image);
imageView.setImageResource(Integer.intValue(list.get(0)));

Within the array will store the names of the pictures, like R.drawable.img1 , R.drawable.img2... Then, use the command:

ImageView img;
img.setImageResource(R.drawable.img1);

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM