我想在我的函数中获取 RANDOM 值,但 n 始终等于 0。我做错了什么?
image = (ImageView) findViewById(R.id.imageView1);
//блок Random
Log.d(Tag, "1");
int NUM_IMAGES=7;
int imageArr[] = new int[NUM_IMAGES];
Log.d(Tag, "2");
imageArr[0] = R.drawable.image1;
imageArr[1] = R.drawable.image2;
imageArr[2] = R.drawable.image3;
imageArr[3] = R.drawable.image4;
imageArr[4] = R.drawable.image5;
imageArr[5] = R.drawable.image6;
imageArr[6] = R.drawable.image7;
Log.d(Tag, "3");
int n = (int)Math.random()*NUM_IMAGES;
Log.d(Tag, "n="+n);
image.setImageResource(imageArr[n]);