0

I'm using two datepicker dialog, one for the start date and the other is for the end date.
The start date dialog works fine, but when I try to execute the second dialog which is the end date, end date dialog also shows up twice.

private void startDateDialog() {
  // Process to get Current Date
  final Calendar c = Calendar.getInstance();
  int mYear = c.get(Calendar.YEAR);
  int mMonth = c.get(Calendar.MONTH);
  int mDay = c.get(Calendar.DAY_OF_MONTH);

  // Launch Date Picker Dialog
  DatePickerDialog dpd = new DatePickerDialog(this,
          new DatePickerDialog.OnDateSetListener() {

            @Override
            public void onDateSet(DatePicker view, int year,
                                  int monthOfYear, int dayOfMonth) {

              startDate = "" + year + "-" + (monthOfYear + 1) + "-" + dayOfMonth;
              endDateDialog();
            }
          }, mYear, mMonth, mDay);
  dpd.setTitle("Start Date");
  dpd.show();
}

private void endDateDialog() {
  // Process to get Current Date
  final Calendar c = Calendar.getInstance();
  int mYear = c.get(Calendar.YEAR);
  int mMonth = c.get(Calendar.MONTH);
  int mDay = c.get(Calendar.DAY_OF_MONTH);

  if (dialog == true) {
    // Launch Date Picker Dialog
    DatePickerDialog dpd = new DatePickerDialog(this,
            new DatePickerDialog.OnDateSetListener() {

              @Override
              public void onDateSet(DatePicker view, int year,
                                    int monthOfYear, int dayOfMonth) {

                startDate = "" + year + "-" + (monthOfYear + 1) + "-" + dayOfMonth;
                InitializeMap();
                dialog = false;
              }
            }, mYear, mMonth, mDay);
    dpd.setTitle("End Date");
    dpd.show();
  } else {

  }
}
CSchulz
  • 10,882
  • 11
  • 60
  • 114
  • Where do you call `endDateDialog()`? I see it is called from `onDateSet` of the start date dialog, anywhere else? Is `onDateSet` called twice? – darnmason Jan 29 '15 at 15:31
  • endDateDialog() must be called if the user clicked on the ok button from the first dialog. how do you fix this? – Norland Mendoza Jan 29 '15 at 15:38
  • Sorry the issue is that the end date dialog is appearing twice, yeah? Debug it and see what code paths are leading to `endDateDialog()` being executed twice. – darnmason Jan 29 '15 at 15:45
  • i did. . i've tried to execute startDateDialog() twice but it's fine. it's just the endDateDialog() – Norland Mendoza Jan 29 '15 at 15:59
  • Stick a breakpoint in `endDateDialog()` and see how it's getting called twice, or confirm that it isn't. – darnmason Jan 29 '15 at 16:01
  • I couldn't find any solution. Is there any other way I could call two datepicker? – Norland Mendoza Jan 29 '15 at 16:21
  • Could this be the `startDateDialog` that is being shown underneath? From what I can see, you don't dismiss/hide the `startDateDialog` EDIT: in the endDateDialog `onDateSet()` you are setting `startDate string`, this should be `endDate` I would assume – Chris Handy Jan 29 '15 at 17:59
  • yeah yeah. . my mistake, but it's the not what causing the problem. – Norland Mendoza Jan 29 '15 at 18:36

0 Answers0