调用Datepicker对话框两次

时间:2015-01-29 15:20:36

标签: android datepickerdialog

我使用两个datepicker对话框,一个用于开始日期,另一个用于结束日期。
开始日期对话框工作正常,但是当我尝试执行第二个对话框即结束日期时,结束日期对话框也会显示两次。

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 {

  }
}

0 个答案:

没有答案