【问题标题】:Android DatePickerDialog date resetAndroid DatePickerDialog 日期重置
【发布时间】:2011-03-14 09:45:06
【问题描述】:

我在 Activity 中使用以下代码来创建 DatePickerDialog。我想在调用第一个活动时显示当前日期。但它工作正常。但之后,对于某些特定条件,我想显示其他日期。如何重置DatePickerDialog日期?

// the callback received when the user "sets" the date in the dialog
    private DatePickerDialog.OnDateSetListener ButtonTestDateListener =
            new DatePickerDialog.OnDateSetListener() {

                public void onDateSet(DatePicker view, int year, 
                                      int monthOfYear, int dayOfMonth) {
                    mYear = year;
                    mMonth = monthOfYear;
                    mDay = dayOfMonth;
                    text_testdate.setText(
                            new StringBuilder()
                                    // Month is 0 based so add 1
                                    .append(formatter.format(mMonth + 1)).append("-")
                                    .append(formatter.format(mDay)).append("-")
                                    .append(mYear).append(" "));
                }
   };

   @Override
   protected Dialog onCreateDialog(int id) {
       switch (id) {
        case 0:
            return new DatePickerDialog(getParent(), ButtonTestDateListener, mYear, mMonth, mDay);
        }
        return null;
   }

.

【问题讨论】:

    标签: android dialog datepicker


    【解决方案1】:

    使用datePickerDialog.updateDate(mYear, mMonth, mDay);

    【讨论】:

      猜你喜欢
      • 2023-03-07
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2016-01-08
      相关资源
      最近更新 更多