Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- <Button
- android:id="@+id/buttonClickMe"
- android:layout_width="match_parent"
- android:layout_height="wrap_content"
- android:layout_below="@+id/textView7"
- android:layout_centerHorizontal="true"
- android:layout_marginTop="18dp"
- android:onClick="sendMessage"
- android:text="@string/button_start" />
- final Button buttonStart = (Button) findViewById(R.id.button1)
- buttonStart.setOnClickListener(new OnClickListener() {
- public void onClick(View arg0) {
- int no = Integer.valueOf(numberField.getText().toString());
- switch (no)
- {
- case 1 : maxRand = 15; // the random number will be between 0 and maxRand
- break;
- case 2 : maxRand = 30;
- break;
- case 3 : maxRand = 50;
- break;
- case 4 : maxRand = 100;
- break;
- default : textField.setText("Invalid Argument, Please try again.");
- break;
- }
- if(maxRand != 0){
- randNumber = (int) (Math.random() * maxRand);
- /*textField.setText("Now click Start button !");
- buttonStart.setVisibility(View.VISIBLE);*/
- startActivity(intent); //This starts a new activity
- }
- }
- });
- public void sendMessage(View view){ //This method is called everytime when the button is clicked
- intent = new Intent(this,ShowResultsActivity.class);
- }
- public void onClick(View arg0) {
- int no = Integer.valueOf(numberField.getText().toString());
- switch (no)
- {
- case 1 : maxRand = 15; // the random number will be between 0 and maxRand
- break;
- case 2 : maxRand = 30;
- break;
- case 3 : maxRand = 50;
- break;
- case 4 : maxRand = 100;
- break;
- default : textField.setText("Invalid Argument, Please try again.");
- break;
- }
- if(maxRand != 0){
- randNumber = (int) (Math.random() * maxRand);
- intent = new Intent(this,ShowResultsActivity.class);
- startActivity(intent); //This starts a new activity
- }
- }
- });
- public void sendMessage(View view){
- //This method is called everytime when the button is clicked
- int no = Integer.valueOf(numberField.getText().toString());
- switch (no)
- {
- case 1 : maxRand = 15; // the random number will be between 0 and maxRand
- break;
- case 2 : maxRand = 30;
- break;
- case 3 : maxRand = 50;
- break;
- case 4 : maxRand = 100;
- break;
- default :
- textField.setText("Invalid Argument, Please try again.");
- // add this to ensure that you won't start activity
- maxRand = 0;
- break;
- }
- if(maxRand != 0){
- randNumber = (int) (Math.random() * maxRand);
- intent = new Intent(this,ShowResultsActivity.class);
- startActivity(intent); //This starts a new activity
- } else {
- // maxRand == 0 ===> ERRORS, update your textField here
- textField.setText("Invalid Argument, Please try again.");
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement