I want to make an app (just for learning purposes) that generates a random message without repeatition.
I have this code inside the onCreate method:
imgbutton2 = (ImageButton) findViewById(R.id.imgbutton2);
int n=3;
int v1[] = new int[n];
v1[0] = 0;
v1[1] = 0;
v1[2] = 0;
int i, j;
for(i=0;i<n;i++){
for(j=0; ;j++){
Random rn = new Random();
int range = 3;
int r = rn.nextInt(range) 1;
if(r != v1[0] & r != v1[1] & r != v1[2]) {
v1[i] = r v1[i];
textView1=new TextView(this);
switch (r) {
case 1:
textView1 = (TextView) findViewById(R.id.textView1);
textView1.setText("Message 1");
break;
case 2:
textView1 = (TextView) findViewById(R.id.textView1);
textView1.setText("Message 2");
break;
case 3:
textView1 = (TextView) findViewById(R.id.textView1);
textView1.setText("Message 3");
break;
}
break;
}
}
imgbutton2.setOnClickListener(new View.OnClickListener(){
public void onClick(View v){
Intent i = null;
}});
}
I put a null function to the imgbutton2 (that's inside the first FOR), just for wait the user click, and continue reading to enter again in the first FOR with the i=1 now), but it's not working.
The idea is generate a new message when the button is clicked.
Can anyone help me?