Warning: file_get_contents(/data/phpspider/zhask/data//catemap/3/android/186.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 显示随机图像_Android - Fatal编程技术网

Android 显示随机图像

Android 显示随机图像,android,Android,我是android的新手。我使用arraylist来显示随机图像 ArrayList<Integer> List = new ArrayList<Integer>(); for(int i=0;i<10;i++) { List.add(i); System.out.println("Random Images"+List.add(i)); } Coll

我是android的新手。我使用arraylist来显示随机图像

ArrayList<Integer> List = new ArrayList<Integer>();
        for(int i=0;i<10;i++) 
        { 
            List.add(i);
            System.out.println("Random Images"+List.add(i));
        }
        Collections.shuffle(List);

        for(int i=0;i<10;i++){
            imageArr[i] = (ImageView)findViewById(id[List.get(i)]);
            System.out.println("Display Images"+List.get(i));
        }
    }

它在logcat中正常运行,但应该如何在模拟器屏幕上显示图像。请建议

阅读一下,看看它是否对您有帮助:

您需要一个图像视图来在屏幕上显示图像。 您可以显示可绘制的位图。。。 最简单的方法是创建main.xml,如下所示:

<ImageView
    android:layout_width="fill_parent"
    android:layout_height="wrap_content"
    android:id="@+id/myImageView" />
然后制作一个可绘制的数组或带有位图的ArryList,随便什么。 获取一个像Math.Random这样的随机值,然后从数组或类似arraylist的列表中获取一个随机图像

Drawable drawable = drawableArray[YOURRANDOMNUMBER];
并将Drawable设置为imageview

imgView .setImageDrawable(drawable);

希望这有帮助:

您希望模拟器正确解释您的系统输出吗?您在Logcat中看到的只是您正确地洗牌了ArrayList,这与图像本身无关。是的,我在logcat中得到了正确的结果。logcat结果是:08-23 15:53:07.053:INFO/System.out453:Random Imagestrue 08-23 15:53:07.053:INFO/System.out453:Random Imagestrue 08-23 15:53:07.053:INFO/System.out453:Display Images608-23 15:53:07.060:INFO/System.out453:显示图像108-23 15:53:07.103:INFO/System.out453:随机图像08-23 15:53:07.103:INFO/System.out453:随机图像08-23 15:53:07.180:INFO/System.out453:显示图像08-23 15:53:07.180:INFO/System.out453:显示图像0
imgView .setImageDrawable(drawable);