I'm trying to randomly display images from an Array. The canvas is rendering but my images are not displaying on the canvas at all. My Drawables are title "one, two, three, four, five"
this is how I initialized my array
int[] array1;
this is my convert function
public static int[] convertIntegers(List<Integer> integers) {
int[] ret = new int[integers.size()];
Iterator<Integer> iterator = integers.iterator();
for (int i = 0; i < ret.length; i++) {
ret[i] = iterator.next().intValue();
}
return ret;
}
This is my render method. The canvas displays but the images do not and I am not get any errors.
public void render(Canvas canvas) {
if (canvas != null) {
canvas.drawRGB(234, 237, 235);
ArrayList<Integer> list = new ArrayList<Integer>();
Random random = new Random();
int[] images = new int[] { R.drawable.one, R.drawable.two,
R.drawable.three, R.drawable.four, R.drawable.five };
for (int i = 0; i < 5; i++) {
while (true) {
int next = random.nextInt(5);
if (!list.contains(next)) {
list.add(images[next]);
break;
}
}
}
array1 = convertIntegers(list);
}
}
I want the Array to display the images randomly throughout the view. Eventually I want each image to have the int value of it's name (i.e. drawable "one" will have value 1) and the Array will randomly display images until the total is 50. But right now I'm just trying to get the images to display on the Canvas.
I'm new to Android dev but was using this thread to help android how to get 4 images in array from ten array of image randomly
Appreciate any help
EDIT: not sure if this will help but I'm using SurfaceView and this in in my MainGamePanel Activity.