I created a DatePickerPreference, i.e. I extended DialogPreference and created a DatePicker object inside and had it working almost perfectly. It changes values when you click t
Since this class extends the DialogPreference
class, it already handles changing the SharedPreference
using the buttons. To correctly update your date variable after the user types the new date, you need to update the SharedPreference
manually.
You can do this as follows:
SharedPreferences prefs = PreferenceManager.getDefaultSharedPreferences(this);
SharedPreferences.Editor preferences = prefs.edit();
preferences.putLong("mdate_key", mDate.getTime());
preferences.commit();
Here, mdate_key will correspond to the DatePickerPreference
key used in the PreferenceActivity
XML file.
I recommend either doing this in onDateChanged()
or onDestroy()
.