title: DatePickerDialog OK button not getting the selected date
body: <p>I have a simple <code>DatePickerDialog</code> that opens when an <code>EditText</code> is opened. After choosing a date and pressing OK, it should be displayed at the same <code>EditText</code>. It works fine if I only use the default dialog where it creates only one button - OK. I added a Cancel button, the problem is that it only gets the current date.</p>
  
  <p>Here's my code:</p>
  
  <pre><code>    private void showDatePicker(String birthdayStr) {
          // TODO Auto-generated method stub
          final Calendar c = Calendar.getInstance();
  
          if (birthdayStr.equals("")) {
              yearStr = c.get(Calendar.YEAR);
              monthStr = c.get(Calendar.MONTH);
              dayStr = c.get(Calendar.DAY_OF_MONTH);
          }
  
          DatePickerDialog.OnDateSetListener datePickerListener = new DatePickerDialog.OnDateSetListener() {
              // when dialog box is closed, below method will be called.
              public void onDateSet(DatePicker view, int selectedYear,
                      int selectedMonth, int selectedDay) {
                  if (isOkayClicked) {
                      birthday.setText(selectedYear + (selectedMonth + 1) + selectedDay);
                      yearStr = selectedYear;
                      monthStr = selectedMonth;
                      dayStr = selectedDay;
                  }
                  isOkayClicked = false;
              }
          };
          DatePickerDialog datePickerDialog = new DatePickerDialog(
                  RegistrationTwoActivity.this, datePickerListener, yearStr,
                  monthStr, dayStr);
  
          datePickerDialog.setButton(DialogInterface.BUTTON_NEGATIVE,
                  getString(R.string.cancel),
                  new DialogInterface.OnClickListener() {
                      public void onClick(DialogInterface dialog, int which) {
                          if (which == DialogInterface.BUTTON_NEGATIVE) {
                              dialog.cancel();
                              isOkayClicked = false;
                          }
                      }
                  });
  
          datePickerDialog.setButton(DialogInterface.BUTTON_POSITIVE, "OK",
                  new DialogInterface.OnClickListener() {
                      public void onClick(DialogInterface dialog, int which) {
                          if (which == DialogInterface.BUTTON_POSITIVE) {
                              isOkayClicked = true;
                              birthday.setText(selectedYear + (selectedMonth + 1) + selectedDay);
                          }
                      }
                  });
          datePickerDialog.setCancelable(false);
          datePickerDialog.show();
      }
  </code></pre>
  
  <p>If I delete the line <code>birthday.setText(selectedYear + (selectedMonth + 1) + selectedDay);</code> under OK or BUTTON_POSITIVE, it works fine. But on some devices, it doesn't set the selected date to the <code>EditText</code> since it was only called inside <code>datePickerListener</code>. So I decided adding the line <code>birthday.setText(selectedYear + (selectedMonth + 1) + selectedDay);</code> under OK or BUTTON_POSITIVE but the problem now is that it only gets the current date.</p>
  
  <p>I'm a little confused by this. If someone could just help me.</p>