Aspiring Developer here
Help! I have been searching around trying to find answers so my code is very uneven, so please, be kind...
My end goal is to create a series of check boxes that will independently populate a String with an random int when checked (not requiring a separate button).
My current step is to populate all of the text views at least when a button is pressed. Then I intend to separate them and work on the if statements for each.
I believe I have literally gone to the end of the internet and have found myself so frustrated by this...
public class MainActivity extends AppCompatActivity {
Button rollButton;
Random randDice = new Random();
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.checkboxactivity);
gridLayout = (GridLayout) findViewById(R.id.gridLayout);
fourTextView = (TextView) findViewById(R.id.fourTextView);
sixTextView = (TextView) findViewById(R.id.sixTextView);
eightTextView = (TextView) findViewById(R.id.eightTextView);
tenTextView = (TextView) findViewById(R.id.tenTextView);
twentyTextView = (TextView) findViewById(R.id.twentyTextView);
hundredTextView = (TextView) findViewById(R.id.hundredTextView);
rollButton.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View v) {
String hundredText = String.valueOf(randDice.nextInt(100 + 1));
hundredTextView.setText(hundredText);
String twentyText = String.valueOf(randDice.nextInt(20 + 1));
twentyTextView.setText(twentyText);
String tenText = String.valueOf(randDice.nextInt(10 + 1));
tenTextView.setText(hundredText);
String eightText = String.valueOf(randDice.nextInt(8 + 1));
eightTextView.setText(eightText);
String sixText = String.valueOf(randDice.nextInt(6 + 1));
sixTextView.setText(sixText);
String fourText = String.valueOf(randDice.nextInt(4 + 1));
fourTextView.Text(fourText);
}
});
}
};
Aucun commentaire:
Enregistrer un commentaire