简体   繁体   English

如何通过一键单击生成多个随机按钮?

[英]How can I generate multiple random buttons with one button click?

I can only generate one number at a time.我一次只能生成一个数字。 How can I generate one number then after a second of delay it will automatically generate another one until I press stop?如何生成一个数字,然后延迟一秒钟后它会自动生成另一个数字,直到我按下停止?

public void generate(View view) throws InterruptedException {
    Random rand = new Random();
    int number = rand.nextInt(20)+1;
    TextView myText = (TextView)findViewById(R.id.textView);
    String myString = String.valueOf(number);

    myText.setText(number);
    TimeUnit.SECONDS.sleep(1);
}

I can only generate one number at a time.我一次只能生成一个数字。 How can I generate one number then after a second of delay it will automatically generate another one until I press stop?如何生成一个数字,然后延迟一秒钟后它会自动生成另一个数字,直到我按下停止?

public void generate(View view) throws InterruptedException {
    Random rand = new Random();
    int number = rand.nextInt(20)+1;
    TextView myText = (TextView)findViewById(R.id.textView);
    String myString = String.valueOf(number);

    myText.setText(number);
    TimeUnit.SECONDS.sleep(1);
}

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM