我想生成1到9之间的随机数,并在一个不同的TextView(用于数独)
我有九个TextView。
private TextView textView1;
private TextView textView2;
private TextView textView3;
private TextView textView4;
private TextView textView5;
private TextView textView6;
private TextView textView7;
private TextView textView8;
private TextView textView9;
public void generateNumbers() {
// Random numbers
int numbers =
textView1.setText();
textView2.setText();
textView3.setText();
textView4.setText();
textView5.setText();
textView6.setText();
textView7.setText();
textView8.setText();
textView9.setText();
}
在某些正方形中,我需要显示3个数字,而在其他正方形中,我需要显示4个数字
val numbers:MutableList<Int> = arrayListOf(1,2,3,4,5,6,7,8,9)
numbers.shuffle()
import java.util.Random;
// Obtain a number between [1 - 9].
Random rand = new Random();
int random = rand.nextInt(9); //This will give value from 0 to 8
random += 1; //This will give value from 1 to 9
textView1.setText(random);
//You can continue like this
textView2.setText(rand.nextInt(9) + 1);
textView3.setText(rand.nextInt(9) + 1);
textView4.setText(rand.nextInt(9) + 1);
......