title: EditText Values Get Written To Database Values On Cancel
body: <p>I have a dialog box that allowing the user to enter in values,  each value gets validated to ensure the correct value has been entered.  However on an invalid entry the values of the EditText are getting written to the SQLite database when the user clicks Cancel.  </p>
  
  <p>This is my code for the Dialog Box:</p>
  
  <pre><code>final AlertDialog alertDialog = alertDialogBuilderUserInput.create();
          alertDialog.show();
  
          alertDialog.getButton( AlertDialog.BUTTON_POSITIVE).setOnClickListener( new View.OnClickListener() {
              @Override
              public void onClick(View v) {
                  //Show Toast Message When No Text Is Entered
                  //Validation Being Done Here
                  if (TextUtils.isEmpty(inputScore.getText().toString())) {
                      inputScore.setText( "0" );
                      //return;
                  }
                  if (TextUtils.isEmpty(inputStrikes.getText().toString())) {
                      inputStrikes.setText( "0" );
                      //return;
                  }
                  if (TextUtils.isEmpty(inputSpares.getText().toString())) {
                      inputSpares.setText( "0" );
                      //return;
                  }
                  if (TextUtils.isEmpty(inputSplits.getText().toString())) {
                      inputSplits.setText( "0" );
                      //return;
                  }
                  if (TextUtils.isEmpty(inputSplitConversions.getText().toString())) {
                      inputSplitConversions.setText( "0" );
                      //return;
                  }
                  if (TextUtils.isEmpty(inputOpenFrames.getText().toString())) {
                      inputOpenFrames.setText( "0" );
                      //return;
                  }
  
                  final int valueScore = Integer.valueOf(inputScore.getText().toString());
                  final int valueStrikes = Integer.valueOf(inputStrikes.getText().toString());
                  final int valueSpares = Integer.valueOf(inputSpares.getText().toString());
                  final int valueSplits = Integer.valueOf(inputSplits.getText().toString());
                  final int valueSplitConversions = Integer.valueOf(inputSplitConversions.getText().toString());
                  final int valueOpenFrame = Integer.valueOf(inputOpenFrames.getText().toString());
                  if (valueScore &gt; 300) {
                      inputScore.setError("Maximum value allowed is 300");
                      //return;
                  } else
                  if (valueStrikes &gt; 12) {
                      inputStrikes.setError("Maximum value allowed is 12");
                      //return;
                  } else
                  if (valueSpares &gt; 10) {
                      inputSpares.setError("Maximum value allowed is 10");
                      //return;
                  } else
                  if (valueSplits &gt; 10) {
                      inputSplits.setError("Maximum value allowed is 10");
                      //return;
                  } else
                  if (valueSplitConversions &gt; 10) {
                      inputSplitConversions.setError("Maximum value allowed is 10");
                      //return;
                  } else
                  if (valueOpenFrame &gt; 10) {
                      inputOpenFrames.setError("Maximum value allowed is 10");
                      //return;
                  } else {
  
                          alertDialog.dismiss();
                      }
  
  
                  //Check If User Is Updating Game
                  //Create New Game
                  if (shouldUpdate &amp;&amp; game != null) {
                      //Update Game By It's Id
                      updateGame(inputScore.getText().toString(), inputStrikes.getText().toString(), inputSpares.getText().toString(), inputSplits.getText().toString(), inputSplitConversions.getText().toString(), inputOpenFrames.getText().toString(), position);
                  } else {
                      createGame(leagueId.getText().toString(), bowlerId.getText().toString(), seriesId.getText().toString(), inputScore.getText().toString(), inputStrikes.getText().toString(), inputSpares.getText().toString(), inputSplits.getText().toString(), inputSplitConversions.getText().toString(), inputOpenFrames.getText().toString());
                  }
                  seriesAverage = db.getSeriesAverage(savedLeagueId, savedBowlerId, savedSeriesId);
                  bowlerAverage = db.getBowlerAverage(savedLeagueId, savedBowlerId);
                  leagueAverage = db.getLeagueAverage(savedLeagueId);
              }
          });
  
      }
  </code></pre>
  
  <p>I would like it to display all the fields that are incorrect at once and not save the values on a cancel.  Can't seem to get this to happen though.  Below is a image of what is currently happening.</p>
  
  <p><a href="https://i.stack.imgur.com/ue0dq.gif" rel="nofollow noreferrer"><img src="https://i.stack.imgur.com/ue0dq.gif" alt="enter image description here"></a></p>