Skip to content

Commit e3491b6

Browse files
Kenneth AnderssonJohan Redestig
authored andcommitted
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.
1 parent 7bb2581 commit e3491b6

File tree

1 file changed

+17
-14
lines changed

1 file changed

+17
-14
lines changed

core/java/android/widget/DatePicker.java

Lines changed: 17 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -94,9 +94,7 @@ public DatePicker(Context context, AttributeSet attrs, int defStyle) {
9494
mDayPicker.setOnChangeListener(new OnChangedListener() {
9595
public void onChanged(NumberPicker picker, int oldVal, int newVal) {
9696
mDay = newVal;
97-
if (mOnDateChangedListener != null) {
98-
mOnDateChangedListener.onDateChanged(DatePicker.this, mYear, mMonth, mDay);
99-
}
97+
notifyDateChanged();
10098
}
10199
});
102100
mMonthPicker = (NumberPicker) findViewById(R.id.month);
@@ -114,9 +112,7 @@ public void onChanged(NumberPicker picker, int oldVal, int newVal) {
114112
mMonth = newVal - 1;
115113
// Adjust max day of the month
116114
adjustMaxDay();
117-
if (mOnDateChangedListener != null) {
118-
mOnDateChangedListener.onDateChanged(DatePicker.this, mYear, mMonth, mDay);
119-
}
115+
notifyDateChanged();
120116
updateDaySpinner();
121117
}
122118
});
@@ -127,9 +123,7 @@ public void onChanged(NumberPicker picker, int oldVal, int newVal) {
127123
mYear = newVal;
128124
// Adjust max day for leap years if needed
129125
adjustMaxDay();
130-
if (mOnDateChangedListener != null) {
131-
mOnDateChangedListener.onDateChanged(DatePicker.this, mYear, mMonth, mDay);
132-
}
126+
notifyDateChanged();
133127
updateDaySpinner();
134128
}
135129
});
@@ -230,11 +224,14 @@ private void reorderPickers(String[] months) {
230224
}
231225

232226
public void updateDate(int year, int monthOfYear, int dayOfMonth) {
233-
mYear = year;
234-
mMonth = monthOfYear;
235-
mDay = dayOfMonth;
236-
updateSpinners();
237-
reorderPickers(new DateFormatSymbols().getShortMonths());
227+
if (mYear != year || mMonth != monthOfYear || mDay != dayOfMonth) {
228+
mYear = year;
229+
mMonth = monthOfYear;
230+
mDay = dayOfMonth;
231+
updateSpinners();
232+
reorderPickers(new DateFormatSymbols().getShortMonths());
233+
notifyDateChanged();
234+
}
238235
}
239236

240237
private static class SavedState extends BaseSavedState {
@@ -376,4 +373,10 @@ private void adjustMaxDay(){
376373
mDay = max;
377374
}
378375
}
376+
377+
private void notifyDateChanged() {
378+
if (mOnDateChangedListener != null) {
379+
mOnDateChangedListener.onDateChanged(DatePicker.this, mYear, mMonth, mDay);
380+
}
381+
}
379382
}

0 commit comments

Comments
 (0)