Warning: file_get_contents(/data/phpspider/zhask/data//catemap/3/android/201.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Android 将imageView设置为新imageView_Android - Fatal编程技术网

Android 将imageView设置为新imageView

Android 将imageView设置为新imageView,android,Android,我试图通过单击显示我的可绘制文件夹中的三幅图像列表。但是,images.get(i)部分给了我一个错误。我不明白。如果我用R.drawable.手提包替换它,它会工作,但用我的arraylist它不会工作(即使它有相同的东西) 就这样试试吧 int images[]={R.drawable.handbag,R.drawable.shoes,R.drawabletie.tie}; 同样的方式 List<Integer> images = new ArrayList<Intege

我试图通过单击显示我的可绘制文件夹中的三幅图像列表。但是,images.get(i)部分给了我一个错误。我不明白。如果我用R.drawable.手提包替换它,它会工作,但用我的arraylist它不会工作(即使它有相同的东西)


就这样试试吧

int images[]={R.drawable.handbag,R.drawable.shoes,R.drawabletie.tie};
同样的方式

List<Integer> images = new ArrayList<Integer>();
images.add(R.drawable.handbag);   // these images have been added
images.add(R.drawable.shoes);
images.add(R.drawable.tie);
List images=new ArrayList();
图片。添加(R.drawable.手提包);//这些图像已经添加
图像。添加(R.可牵引鞋);
图像。添加(R.可拉伸。领带);

就这样试试吧

int images[]={R.drawable.handbag,R.drawable.shoes,R.drawabletie.tie};
同样的方式

List<Integer> images = new ArrayList<Integer>();
images.add(R.drawable.handbag);   // these images have been added
images.add(R.drawable.shoes);
images.add(R.drawable.tie);
List images=new ArrayList();
图片。添加(R.drawable.手提包);//这些图像已经添加
图像。添加(R.可牵引鞋);
图像。添加(R.可拉伸。领带);

创建图像数组,如下所示

private static int images[]={R.drawable.handbag,R.drawable.shoes,R.drawabletie.tie};
然后按如下方式使用

image.setImageResource((images[i]));
或按如下所示创建ArrayList

List<Integer> images = new ArrayList<Integer>();
List images=new ArrayList();

创建图像数组,如下所示

private static int images[]={R.drawable.handbag,R.drawable.shoes,R.drawabletie.tie};
然后按如下方式使用

image.setImageResource((images[i]));
或按如下所示创建ArrayList

List<Integer> images = new ArrayList<Integer>();
List images=new ArrayList();

将Arraylist的类型更改为整数,如下所示:

  ArrayList<Integer> images = new ArrayList<>();
arraylistimages=newarraylist();

将Arraylist的类型更改为整数,如下所示:

  ArrayList<Integer> images = new ArrayList<>();
arraylistimages=newarraylist();


您遇到的错误是什么?发布日志。另外,请说明如何创建i和图像请检查图像的arraylist类型imageview中的ImageStimageResource(int)不能应用于(java.lang.object)。数组列表声明为imageview您遇到了什么错误?发布日志。同时请说明如何创建i和图像请检查图像的arraylist类型imageview中的ImageStimageResource(int)无法应用于(java.lang.object)。数组列表声明为imageview,但该列表不起作用,因为它仍将其视为“对象”不是吗this@ankitagrawalInteger是一个对象。请尝试我下面的建议Integer是一个int类型的对象,这样您就可以在@user5716019安全地使用它,因为它仍然将其视为“对象”,所以它不起作用不是吗this@ankitagrawalInteger是一个对象。请尝试我下面的建议Integer是int类型的对象,这样您就可以安全地使用它@user5716019Hey this worked。你能告诉我为什么数组工作而不是ArrayList吗?当你简单地添加int值和检索int值时,数组工作。ArrayList不起作用,因为某个地方有一个类型不匹配第一个-使用了正常的arrayCheck my comment在您的问题中,它起作用的原因是什么。你能告诉我为什么数组工作而不是ArrayList吗?当你简单地添加int值和检索int值时,数组工作。ArrayList不起作用,因为某个地方有一个类型不匹配第一个-使用了普通的Array检查我在你的问题中的评论它起作用的原因是什么