I am trying a basic app in android. The following code prints out 32, 33, 34 and 35 values for the randomNum. Why is it behaving this way ?
Button button = (Button) findViewById(R.id.button);final String[] lyrics = {"Caught in a Landslide!","No"," Escape","From Reality..."};
button.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View v) {
Random rando = new Random();
int randomNum = rando.nextInt(4);
textView.setText(randomNum + ' ' + lyrics[randomNum]);
}
});
P.S. - It is working fine and printing out the values from lyrics array only. just the randomNum is printed weirdly! \
Aucun commentaire:
Enregistrer un commentaire