I am having a hard time to generate 6 random numbers between 1 -25 using android studio. I would like it to be displayed in one text box. Also I don't want to get 0 and no repeats...can anyone help
This is my coding:
import android.os.Bundle;
import android.support.v7.app.AppCompatActivity;
import android.view.View;
import android.widget.TextView;
import java.util.Random;
public class MainActivity extends AppCompatActivity {
TextView txtrandom;
Button btnClick;
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main);
txtrandom = (TextView) findViewById(textViewRandom);
btnClick = (Button) findViewById(R.id.buttonClick);
btnClick.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View v) {
Random r = new Random();
int n = r.nextInt(25) + 1;
txtrandom.setText(String.valueOf(n));
}
});
Toast.makeText(this, "Good Luck!", Toast.LENGTH_SHORT).show();
}
/**
* Resets the number to 0
*/
public void resetScore(View view) {
int textViewRandom = 0;
displayRandom(textViewRandom);
Toast.makeText(this, "Pick Again!", Toast.LENGTH_SHORT).show();
return;
}
/**
* Displays the random number.
*/
public void displayRandom(int score) {
TextView scoreView = (TextView) findViewById(R.id.textViewRandom);
scoreView.setText(String.valueOf(score));
}
}