im novice to android.For displaying random images i used 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));
}
}
it is running correctly in logcat but what should do to display images on emulator screen. Pls Suggest
You will need an ImageView to display Images on the Screen.
You can display drawable, bitmaps, …
The easiest way to do this create your main.xml like this:
Then call in your code (maybe in the onCreate):
Then make a Drawable Array or an ArryList with bitmaps, whatever.
Get a Random value (like
Math.random()) and fetch a random image from array or arraylist likeand set the Drawable to the imageview.
Hope this helps 🙂