I recently started with android programming, with just basic knowledge in java. I'm having trouble with my code,What I'm aiming is to display a randomly chosen text that's already programmed in my array after the button is clicked (onclick event).
public void magicbegins() //
{
int min = 0;
int max = 3;
Random r = new Random();
int rand = r.nextInt(max - min + 1) + min;
//generating random number from 0 to 3 to use as index in later event
String[] magictext = {"yes", "no", "maybe"};
TextView text = (TextView) findViewById(R.id.textView1);
//using the generated number as index for programmed string array
text.setText(magictext[rand]);
}
If any case this codes is not recommendable to use, will anyone provide a sample script that would do similar from what I aim at very least?
int rand = r.nextInt( max - min ) + min;. In this specific case, you can just userand = r.nextInt( max );