title: Generating integers properly on click
body: <p>I am having trouble with my code regarding integers I generate when a  function is called - my code is meant to be a mathematical game where user answers random arithmetic questions with numbers from 1 to 12 and that I can do but the code seems to be generating new random values before allowing the user to answer to a previous question, meaning the user answers to the next question that is not shown on screen. I think it's described better inside the code where I commented on specific lines. </p>
  
  <pre><code>public class MainActivity extends AppCompatActivity {
  
  
  
  
  Random r = new Random();
  int points1 = 0;
  
  
  @Override
  protected void onCreate(Bundle savedInstanceState) {
      super.onCreate(savedInstanceState);
      setContentView(R.layout.activity_main);
  
      int value1 = r.nextInt(12 - 1) + 1;             //1st randomized set of values
      int value2 = r.nextInt(12 - 1) + 1;             // ^
      TextView Number1 = findViewById(R.id.number1);
      Number1.setText(""+value1);                            //assigns randomized values to TextViews
      TextView Number2 = findViewById(R.id.number2);
      Number2.setText(""+value2);                            // ^^
  
  }
  
  public void onSubmitCheck (View view) {
      reset();                                               //When button Submit is clicked
  
  }       //^ ^ Issue starts here when we click "submit" - the code generates new random values before checking the old ones against the mathematical expression in line 50..
          //..meaning the user is already answering to the SECOND question before even attempting the first one.
  
  public void reset(){
      int value1 = r.nextInt(12 - 1) + 1;            //Assigns 2nd randomized values
      int value2 = r.nextInt(12 - 1) + 1;            // ^
          TextView Number1 = findViewById(R.id.number1);
          Number1.setText("" + value1);
          TextView Number2 = findViewById(R.id.number2);
          Number2.setText("" + value2);
      TextView Answer = findViewById(R.id.Answer);
      TextView displayPoints = findViewById(R.id.points);
      EditText Attempt = findViewById(R.id.Attempt);
      int userAnswer = Integer.parseInt(Attempt.getText().toString());    //compares inputted value to an answer from line 50
      if (userAnswer == value1 + value2) {                                    //LINE 50
          Answer.setText("Correct!");
          point();
          displayPoints.setText(""+ points1);
  
      } else {
          Answer.setText("Wrong :( Answer was: " + (value1 + value2));
      }
  </code></pre>
  
  <p>So finally, what I am trying to achieve is generated values on creation (onCreate) that user can answer, then after the users input and submition the app should generate new values and allow the user to answer again. I am not expecting a full work done for me but ideas that could lead me towards an answer as I really would like to learn and understand my problem.</p>
  
  <p>I tried different things but I guess it's just my experience and knowledge that is blocking me from finding a solution - I am a begginer and self-taught.</p>
  
  <p><strong>EDIT FOR RANDOM OPERATOR ISSUE;</strong></p>
  
  <p>public class MainActivity extends AppCompatActivity {</p>
  
  <pre><code>Random r = new Random();
  
  
  int points1 = 0;
  int value1, value2;
  TextView Number1;
  TextView Number2;
  TextView Answer;
  TextView displayPoints;
  EditText Attempt;
  TextView Operator;
  
  @Override
  protected void onCreate(Bundle savedInstanceState) {
      super.onCreate(savedInstanceState);
      setContentView(R.layout.activity_main);
  
      Number1 = findViewById(R.id.number1);
      Number2 = findViewById(R.id.number2);
      Answer = findViewById(R.id.Answer);
      Operator = findViewById(R.id.operator);
      displayPoints = findViewById(R.id.points);
      Attempt = findViewById(R.id.Attempt);
  
      value1 = r.nextInt(12 - 1) + 1;             
      value2 = r.nextInt(12 - 1) + 1;             
      Number1.setText("" + value1);                            
      Number2.setText("" + value2);
  
      int operator = r.nextInt(4 - 1) + 1;        //HERE
      switch (operator)
      {
          case 1: operator = '+';
              break;
          case 2: operator = '-';
              break;
          case 3: operator = '*';
              break;
          case 4: operator = '/';
              break;
      }
      Operator.setText("" + operator);
  }
  
  
  
  
  public void onSubmitCheck(View view) {
      reset();
  
  }
  
  public void reset() {
  
  
      int operator = r.nextInt(4 - 1) + 1;                   //here
      switch (operator)
      {
          case 1: operator = '+';
              break;
          case 2: operator = '-';
              break;
          case 3: operator = '*';
              break;
          case 4: operator = '/';
              break;
      }
  
      int userAnswer = Integer.parseInt(Attempt.getText().toString());
      if (userAnswer == value1 + operator + value2) {
          Answer.setText("Correct!");
          point();
          displayPoints.setText("" + points1);
  
      } else {
          Answer.setText("The answer was: " + (value1 + value2));
      }
  
      value1 = r.nextInt(12 - 1) + 1;             
      value2 = r.nextInt(12 - 1) + 1;            
      Number1.setText("" + value1);
      Number2.setText("" + value2);
      Operator.setText("" + Operator);
  
  }
  public void point() {
      points1 = points1 + 1;
  
  }
  
  
  public void onSubmitNext(View view) {
      reset();
  }
  </code></pre>
  
  <p>}</p>