【发布时间】:2013-06-21 10:15:48
【问题描述】:
我正在使用随机数将我的 imageButton 设置为随机图像。我想知道是否有办法在drawable的文件路径中使用随机int。此代码给出了无效整数的运行时错误,但会编译。
Random generator = new Random();
int chooseFirstPicture = generator.nextInt(2);
int imagePath1 = Integer.parseInt("R.drawable.image" + chooseFirstPicture);
btn1.setBackgroundResource(imagePath1);
【问题讨论】:
标签: android random path numbers drawable