使用ImageView的ArrayList中的Android加载图像 [英] Android Load image on ImageView using arraylist
问题描述
这可能是我可能会再次忽略了一个问题,但如果你能帮助我解决这个问题,我将非常感激。
使用这种code,以获得可绘制的图像,并把它发送到Imageview.setImageResource(其中我的ImageView是一个gridview内);一切正常
私人整数[] = imageIDs {
//R.drawable.image1,
R.drawable.image2,
R.drawable.image3,
R.drawable.image4,
R.drawable.image5,
R.drawable.image6,
R.drawable.Image7,
};//这里是我的另一个code调用imageIDs为ImageResource
ImageView的IV =(ImageView的)v.findViewById(R.id.grid_item_picture);
iv.setImageResource(imageIDs [位置]);
//位置的GridView的从0开始的默认值
现在我要完成的是删除阵列,并将其转换,因为需要这些数据里面是动态的简单的ArrayList。所以,香港专业教育学院创建这些新的code
的ArrayList<串GT; array_image =新的ArrayList<串GT;();
array_image.add(R.drawable.image6);
array_image.add(R.drawable.image1);
和ImageView的ImageResource设置为此code
iv.setImageResource(array_image获得(位置));
我收到一个错误说:
在类型ImageView的方法setImageResource(INT)是不适用的参数(对象)
你能不能帮我解决/看着办吧?
块引用>解决方案您正在定义弦乐的ArrayList。但是你需要整数作为资源标识符。
做到这一点,而不是像这样;
的ArrayList<整数GT; array_image =新的ArrayList<整数GT;();
array_image.add(R.drawable.image6);
array_image.add(R.drawable.image1);This might be a problem that I might overlooked again but if you could help me solve it, I will be very thankful. Using this code to get images from drawable and sending it to Imageview.setImageResource (in which my Imageview is inside a gridview);everything works well
private Integer[] imageIDs = { //R.drawable.image1, R.drawable.image2, R.drawable.image3, R.drawable.image4, R.drawable.image5, R.drawable.image6, R.drawable.Image7, }; //Here is my another code to call imageIDs as ImageResource ImageView iv = (ImageView)v.findViewById(R.id.grid_item_picture); iv.setImageResource(imageIDs[position]); //position is a default value of gridview starting from 0
Now what I trying to accomplish is to delete that array and convert it to arraylist simply because need these inside data to be dynamic. And so ive created these new code
ArrayList<String> array_image = new ArrayList<String>(); array_image.add("R.drawable.image6"); array_image.add("R.drawable.image1");
and set the ImageView ImageResource to this code
iv.setImageResource(array_image .get(position));
I am getting an error saying:
The method setImageResource(int) in the type ImageView is not applicable for the arguments (Object) Can you help me fix/figure it out?
解决方案You are defining an ArrayList for Strings. However you need integers as resource identifiers.
Do it instead like this;
ArrayList<Integer> array_image = new ArrayList<Integer>(); array_image.add(R.drawable.image6); array_image.add(R.drawable.image1);
这篇关于使用ImageView的ArrayList中的Android加载图像的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!