I am trying to make a small app which can give randomly added sentences for me and my friend when we hang out together. I was able to do it by use arrays and random function. The problem is the button only works at the first time I push the button, if I push it again nothing change. I am a newbie to Android and Java so I do not understand much. Here is my code:
Random r = new Random(); //Khai báo biến random
n = r.nextInt(14) + 0 ; //hàm tạo biến random
//Thêm phần tử vào chuỗi
mangtrochoi[0]=("do A");
mangtrochoi[1]=("do B");
mangtrochoi[2]=("do C");
mangtrochoi[3]=("do D");
mangtrochoi[4]=("do E");
mangtrochoi[5]=("do F");
/* mangtrochoi[6]=("đéo được đánh sd");
mangtrochoi[7]=("đánh Thảo 10 cái");
mangtrochoi[8]=("đánh Nhân 10 cái");
mangtrochoi[9]=("đánh Nguyên 10 cái");
mangtrochoi[11]=("đánh Bun 10 cái");
mangtrochoi[12]=("đánh Tiến 10 cái");
mangtrochoi[13]=("đánh Giang 10 cái");
mangtrochoi[14]=("đéo được đánh sd");*/
//Buoc 3: viet code
BTNrandom.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View v) {
TVhienthi.setText(mangtrochoi[n]);
}
});