简体   繁体   English

如何从ArrayList将图像设置为ImageView <String> 在android中?

[英]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. 我正在创建一个用于图像共享的android应用程序。在mainactivity中,一个gridview显示名为img Arraylist<String> img 。当我单击任何图像时,另一个活动称为只有一个ImageView可以显示我在mainactivity中选择的图像,但是我无法使用ImageView.setImageResource(img.get(currentImage))方法在ImageView中设置图像。其中img是字符串类型的ArrayList

any help will be appreciate. 任何帮助将不胜感激。

You can create an ArrayList of Integers and then easily assign the image to the imageview: 您可以创建一个整数数组列表,然后轻松地将图像分配给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: 在数组中将存储图片的名称,例如R.drawable.img1,R.drawable.img2 ...然后,使用命令:

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

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

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