I wrote a custom PreferenceDialog that includes two TimePickers, an EditText, a few CheckBoxes, and a scrollview parent.
Everything works fine, but when the screen orientation changes the timepickers reset to 0 while the other controls retain their state. The values returned by getCurrentHour and getCurrentMinute are the expected values even after the orientation change.
If you scroll up and down the timepickers will eventually redraw and display the correct numbers. Also, if you manually change from 24 hour format to 12 hour format (or vice versa) the timepickers will display the correct value.
Does anyone have an idea on what's going on?
FINALLY figured it out. If you're using a TimePicker within a DialogPreference all you have to do is override the showDialog method and set the currentHour and currentMinute there.
Like this:
@Override
protected void showDialog(Bundle state) {
super.showDialog(state);
mBeginShiftTp.setCurrentHour(mBeginShiftTp.getCurrentHour());
mBeginShiftTp.setCurrentMinute(mBeginShiftTp.getCurrentMinute());
mEndShiftTp.setCurrentHour(mEndShiftTp.getCurrentHour());
mEndShiftTp.setCurrentMinute(mEndShiftTp.getCurrentMinute());
}