【问题标题】:How to display generate random number on screen如何在屏幕上显示生成随机数
【发布时间】:2013-12-01 17:43:18
【问题描述】:

我正在尝试创建一个会生成随机数的应用。我发现这会生成数字编码,并且运行良好。但是,当我想在布局中显示生成编号时遇到问题。

例如,生成器会生成两个数字; numberOne=3 和 numberTwo=1。然后它将在布局页面上显示图像视图编号 3 和图像视图编号 1。由于我是新手,所以如何根据生成的数字显示数字的图像视图。谢谢:)

生成数字编码

Random randomNum=new Random();
int numberOne;

numberOne=1+randomNum.nextInt(10);
System.out.println(numberOne + " ");

这是展示的例子

【问题讨论】:

    标签: android layout random numbers imageview


    【解决方案1】:

    您只需要将图像加载到已定义的 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);
    

    【讨论】:

      猜你喜欢
      • 2011-01-25
      • 1970-01-01
      • 1970-01-01
      • 2014-04-07
      • 1970-01-01
      • 1970-01-01
      • 2013-10-26
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多