title: Android, get values from DatePickerDialog from within .setButton() method?
body: <p>I have a DatePickerDialog, which I call in the following way:</p>
  
  <pre><code>DatePickerDialog dialog = new DatePickerDialog(EditActivity.this, mDateSetListener, 2015, 1, 10);
  dialog.setButton(
      DialogInterface.BUTTON_NEGATIVE, "Cancel",
      new DialogInterface.OnClickListener() {
          public void onClick(DialogInterface dialog, int which) {
              if (which == DialogInterface.BUTTON_NEGATIVE) {
              }
          }
      });
  dialog.setButton(
      DialogInterface.BUTTON_POSITIVE, "OK",
      new DialogInterface.OnClickListener() {
          public void onClick(DialogInterface dialog, int which) {
              if (which == DialogInterface.BUTTON_POSITIVE) {
                  ... Save values from picker here...
              }
          }
      });
  dialog.show();
  </code></pre>
  
  <p>where the listener is:</p>
  
  <pre><code>private DatePickerDialog.OnDateSetListener mDateSetListener = new DatePickerDialog.OnDateSetListener() {
      public void onDateSet(DatePicker view, int year, int monthOfYear, int dayOfMonth) {
      }
  };
  </code></pre>
  
  <p>The <code>onDateSet</code> method is called <em>every time</em>... on OK, on CANCEL, on DISMISS (no button pressed). </p>
  
  <p>I would only like the values to be registered and stored if the user presses "OK", and thus the <code>DialogInterface.BUTTON_POSITIVE</code>. It works great, but is there an in-built method with pickerDialogs to get the values?</p>
  
  <p>What I'm having to do right now is put a boolean inside the positive button method:</p>
  
  <pre><code>if(which == DialogInterface.BUTTON_POSITIVE){mOKClicked = true;}
  </code></pre>
  
  <p>and then test for it in the <code>onDateSet</code>:</p>
  
  <pre><code>if(mOKClicked){... save values...}
  </code></pre>
  
  <p>As far as I can tell, the <code>DialogInterface.BUTTON_POSITIVE</code> is called before the <code>onDateSet</code>, but I'm not sure if it is always the case. I would prefer an in-built call to gather the values set in the picker, if such a thing exists.</p>
  
  <p>Thanks in advance!</p>