I might be missing something but this seems to always persist the value even if you cancel the TimePicker. I changed onTimeChanged to store to a local variable and then did a @Override on onDialogClosed to get the state of the dialog.
If the user said 'ok' then persist the string (In my implementation I didn't make it persist by default, hence the 'isPersistent()'). If the user canceled then I change nothing
private int mHour = 0, mMinute = 0;
@Override
public void onTimeChanged(TimePicker view, int hour, int minute) {
mHour = hour;
mMinute = minute;
}
@Override
public void onDialogClosed(boolean positiveResult) {
if( positiveResult ) {
if( isPersistent() )
persistString(mHour + ":" + mMinute);
mValueText.setText( getNiceTimestring() );
}
}
Cancel behavior
I might be missing something but this seems to always persist the value even if you cancel the TimePicker. I changed onTimeChanged to store to a local variable and then did a @Override on onDialogClosed to get the state of the dialog.
If the user said 'ok' then persist the string (In my implementation I didn't make it persist by default, hence the 'isPersistent()'). If the user canceled then I change nothing
private int mHour = 0, mMinute = 0; @Override public void onTimeChanged(TimePicker view, int hour, int minute) { mHour = hour; mMinute = minute; } @Override public void onDialogClosed(boolean positiveResult) { if( positiveResult ) { if( isPersistent() ) persistString(mHour + ":" + mMinute); mValueText.setText( getNiceTimestring() ); } }