dev_android
dev_android

Reputation: 8818

Android DatePickerDialog date reset

I am using the following code within an Activity to creat a DatePickerDialog. I want to show the current date when 1st acitivity is called. But it is working fine. But afterwards, for some specific conditions, I want to show some other date. How to reset DatePickerDialog date?

// 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;
   }

.

Upvotes: 0

Views: 2779

Answers (1)

dev_android
dev_android

Reputation: 8818

use datePickerDialog.updateDate(mYear, mMonth, mDay);

Upvotes: 4

Related Questions