这可能是一个我可能会再次忽略的问题,但如果你能帮助我解决它,我将非常感激。 使用此代码从可绘制对象中获取图像并将其发送到 Imageview.setImageResource(其中我的 Imageview 在 gridview 中);一切正常
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
现在我想要完成的是删除该数组并将其转换为 ArrayList 只是因为需要这些内部数据是动态的。所以我创建了这个新代码
ArrayList<String> array_image = new ArrayList<String>();
array_image.add("R.drawable.image6");
array_image.add("R.drawable.image1");
并将 ImageView ImageResource 设置为此代码
iv.setImageResource(array_image .get(position));
我收到一条错误消息:
The method setImageResource(int) in the type ImageView is not applicable for the arguments (Object) Can you help me fix/figure it out?
最佳答案
您正在为字符串定义一个 ArrayList。但是,您需要整数作为资源标识符。
改为这样做;
ArrayList<Integer> array_image = new ArrayList<Integer>();
array_image.add(R.drawable.image6);
array_image.add(R.drawable.image1);
关于java - Android 使用 arraylist 在 ImageView 上加载图像,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/12085800/