Android 在洗牌Imageview数组列表后获取图像的位置

Android 在洗牌Imageview数组列表后获取图像的位置,android,Android,这给了我错误的结果 ReciverI[i].setBackgroundResource(images2[Integer.parseInt(pic.get(i).toString())]); 对不起,我没注意。你只要把你的列表列出来就行了。 正如您的代码片段现在所显示的那样,拥有整数数组列表是没有用的。我重写了代码 解决方案1 ReciverI[i].setBackgroundResource(pic.get(i)) Integer[]images2={R.drawable.erro

这给了我错误的结果

    ReciverI[i].setBackgroundResource(images2[Integer.parseInt(pic.get(i).toString())]);
对不起,我没注意。你只要把你的
列表列出来
就行了。 正如您的代码片段现在所显示的那样,拥有整数数组列表是没有用的。

我重写了代码

解决方案1

ReciverI[i].setBackgroundResource(pic.get(i)) 
Integer[]images2={R.drawable.error,R.drawable.reviewp,R.drawable.bowl,R.drawable.ic_action_search};
List pic=Arrays.asList(images2);
收藏。洗牌(图片);

对于(int i=0;i),类型视图中的方法setBackgroundResource(int)不适用于参数(int[]);显示此错误是因为您传递的是整个整数数组,而不是1 int。只需创建列表即可。请执行此操作,我完全困惑,我从早上开始执行此操作这不是工作列表pic=Arrays.asList(images2);我用的是这个,你在里面改变了什么?你能不能再详细一点。你想得到什么位置?你为什么不给我自己?我想得到0,1,2,3类型视图中的方法setBackgroundResource(int)不适用于参数(int[])@Rohit只需将int[]改为整数[]一切都会好起来的!类型不匹配:无法从列表转换为List@Rohit哪一个正在使用?解决方案1或2我测试了这两个问题,所有问题都解决了correct@Rohit请确保你做的每件事都和我一样
ReciverI[i].setBackgroundResource(pic.get(i)) 
Integer[] images2 = {R.drawable.wrong, R.drawable.reviewp, R.drawable.bowl,R.drawable.ic_action_search};
List<Integer> pic=Arrays.asList(images2);
Collections.shuffle(pic);
for(int i = 0 ; i <= pic.size() ; i++){
ReciverI[i].setBackgroundResource(pic.get(i))
}
List<Integer> pic = new ArrayList<Integer>();
        for (int index = 0; index < images2.length; index++)
        {
            pic.add(images2[index]);
        } 
        Collections.shuffle(pic);
        for(int i = 0 ; i <= pic.size() ; i++){
          ReciverI[i].setBackgroundResource(pic.get(i))
        }