Advertisement
Guest User

Untitled

a guest
Apr 17th, 2014
42
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 3.31 KB | None | 0 0
  1. <Button
  2. android:id="@+id/buttonClickMe"
  3. android:layout_width="match_parent"
  4. android:layout_height="wrap_content"
  5. android:layout_below="@+id/textView7"
  6. android:layout_centerHorizontal="true"
  7. android:layout_marginTop="18dp"
  8. android:onClick="sendMessage"
  9. android:text="@string/button_start" />
  10.  
  11. final Button buttonStart = (Button) findViewById(R.id.button1)
  12. buttonStart.setOnClickListener(new OnClickListener() {
  13.  
  14. public void onClick(View arg0) {
  15.  
  16. int no = Integer.valueOf(numberField.getText().toString());
  17.  
  18. switch (no)
  19. {
  20. case 1 : maxRand = 15; // the random number will be between 0 and maxRand
  21. break;
  22. case 2 : maxRand = 30;
  23. break;
  24. case 3 : maxRand = 50;
  25. break;
  26. case 4 : maxRand = 100;
  27. break;
  28. default : textField.setText("Invalid Argument, Please try again.");
  29. break;
  30. }
  31.  
  32. if(maxRand != 0){
  33. randNumber = (int) (Math.random() * maxRand);
  34. /*textField.setText("Now click Start button !");
  35. buttonStart.setVisibility(View.VISIBLE);*/
  36. startActivity(intent); //This starts a new activity
  37. }
  38. }
  39. });
  40.  
  41. public void sendMessage(View view){ //This method is called everytime when the button is clicked
  42.  
  43. intent = new Intent(this,ShowResultsActivity.class);
  44. }
  45.  
  46. public void onClick(View arg0) {
  47.  
  48. int no = Integer.valueOf(numberField.getText().toString());
  49.  
  50. switch (no)
  51. {
  52. case 1 : maxRand = 15; // the random number will be between 0 and maxRand
  53. break;
  54. case 2 : maxRand = 30;
  55. break;
  56. case 3 : maxRand = 50;
  57. break;
  58. case 4 : maxRand = 100;
  59. break;
  60. default : textField.setText("Invalid Argument, Please try again.");
  61. break;
  62. }
  63.  
  64. if(maxRand != 0){
  65. randNumber = (int) (Math.random() * maxRand);
  66. intent = new Intent(this,ShowResultsActivity.class);
  67. startActivity(intent); //This starts a new activity
  68. }
  69. }
  70. });
  71.  
  72. public void sendMessage(View view){
  73. //This method is called everytime when the button is clicked
  74. int no = Integer.valueOf(numberField.getText().toString());
  75.  
  76. switch (no)
  77. {
  78. case 1 : maxRand = 15; // the random number will be between 0 and maxRand
  79. break;
  80. case 2 : maxRand = 30;
  81. break;
  82. case 3 : maxRand = 50;
  83. break;
  84. case 4 : maxRand = 100;
  85. break;
  86. default :
  87. textField.setText("Invalid Argument, Please try again.");
  88. // add this to ensure that you won't start activity
  89. maxRand = 0;
  90. break;
  91. }
  92.  
  93. if(maxRand != 0){
  94. randNumber = (int) (Math.random() * maxRand);
  95. intent = new Intent(this,ShowResultsActivity.class);
  96. startActivity(intent); //This starts a new activity
  97. } else {
  98. // maxRand == 0 ===> ERRORS, update your textField here
  99. textField.setText("Invalid Argument, Please try again.");
  100. }
  101. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement