我正在尝试创建一个会生成随机数的应用。我发现这生成了数字编码,它工作得很好。但是,当我想在布局中显示生成编号时,我遇到了问题。
例如,生成器将生成两个数字; numberOne = 3,numberTwo = 1。然后它将在布局页面上显示imageview编号3和imageview编号1。由于我是新手,所以如何根据生成的数字显示数字的图像视图。谢谢:))
生成数字编码
Random randomNum=new Random();
int numberOne;
numberOne=1+randomNum.nextInt(10);
System.out.println(numberOne + " ");
这是显示的示例
答案 0 :(得分:0)
您只需将图像加载到已定义的ImageView中。
// fetch image resource id
// first parameter is the image name without the extension
int id = getResources().getIdentifier("image_name", "drawable", getPackageName());
// assign it to ImageView
imageView.setImageResource(id);