From e3491b6b5f1d3fb871074766597b275d9f682faa Mon Sep 17 00:00:00 2001 From: Kenneth Andersson Date: Fri, 5 Mar 2010 09:16:24 +0100 Subject: [PATCH] Title in DatePickerDialog used in Settings application not updated correctly The DatePickerDialog in the Settings application is not updated correctly if you follow the following step-by-step: 1. Enter Date option in settings application 2. Modify the values of the date, then cancel the changes 3. Once again enter the date option and you can see that the title in the dialog has not been updated correctly. This is due to a missing call to onDateChanged callback in the DatePicker class. Solution was to add the notify call when updateTime has been called. --- core/java/android/widget/DatePicker.java | 31 +++++++++++++----------- 1 file changed, 17 insertions(+), 14 deletions(-) diff --git a/core/java/android/widget/DatePicker.java b/core/java/android/widget/DatePicker.java index 5e76cc3a28af9..736475e6fecff 100644 --- a/core/java/android/widget/DatePicker.java +++ b/core/java/android/widget/DatePicker.java @@ -94,9 +94,7 @@ public class DatePicker extends FrameLayout { mDayPicker.setOnChangeListener(new OnChangedListener() { public void onChanged(NumberPicker picker, int oldVal, int newVal) { mDay = newVal; - if (mOnDateChangedListener != null) { - mOnDateChangedListener.onDateChanged(DatePicker.this, mYear, mMonth, mDay); - } + notifyDateChanged(); } }); mMonthPicker = (NumberPicker) findViewById(R.id.month); @@ -114,9 +112,7 @@ public class DatePicker extends FrameLayout { mMonth = newVal - 1; // Adjust max day of the month adjustMaxDay(); - if (mOnDateChangedListener != null) { - mOnDateChangedListener.onDateChanged(DatePicker.this, mYear, mMonth, mDay); - } + notifyDateChanged(); updateDaySpinner(); } }); @@ -127,9 +123,7 @@ public class DatePicker extends FrameLayout { mYear = newVal; // Adjust max day for leap years if needed adjustMaxDay(); - if (mOnDateChangedListener != null) { - mOnDateChangedListener.onDateChanged(DatePicker.this, mYear, mMonth, mDay); - } + notifyDateChanged(); updateDaySpinner(); } }); @@ -230,11 +224,14 @@ public class DatePicker extends FrameLayout { } public void updateDate(int year, int monthOfYear, int dayOfMonth) { - mYear = year; - mMonth = monthOfYear; - mDay = dayOfMonth; - updateSpinners(); - reorderPickers(new DateFormatSymbols().getShortMonths()); + if (mYear != year || mMonth != monthOfYear || mDay != dayOfMonth) { + mYear = year; + mMonth = monthOfYear; + mDay = dayOfMonth; + updateSpinners(); + reorderPickers(new DateFormatSymbols().getShortMonths()); + notifyDateChanged(); + } } private static class SavedState extends BaseSavedState { @@ -376,4 +373,10 @@ public class DatePicker extends FrameLayout { mDay = max; } } + + private void notifyDateChanged() { + if (mOnDateChangedListener != null) { + mOnDateChangedListener.onDateChanged(DatePicker.this, mYear, mMonth, mDay); + } + } }