3

My program shows classic android.app.TimePickerDialog and listens to OnTimeSetListener.onTimeSet() . After migrating from Android 4.3 to 5.1 I noticed that typing minutes using keyboard and pressing "OK" results wrong values passed to onTimeSet() handler. However, if I press Enter on keyboard before pressing OK button in the dialog (or click on the hours input or just use the spinner), the values are correct.

I think it has something to do with NumberPicker focus not cleared, when user presses OK.

It is inconvenient to use the spinner for minutes or additionally press Enter on keyboard. How to get my values accepted with OK button alone?

import android.app.*;
...

private final DatePickerDialog.OnDateSetListener mDateSetListener = new DatePickerDialog.OnDateSetListener() {
    public void onDateSet(DatePicker view, int year, int monthOfYear, int dayOfMonth) {
        ...
    }
}

@Override
protected Dialog onCreateDialog(int id) {
    switch (id) {
        case TIMEPICKER_DIALOG:
        return new TimePickerDialog(ChannelActivity.this, mTimeSetListener, day.get(Calendar.HOUR_OF_DAY), day.get(Calendar.MINUTE), true);
    }
    return super.onCreateDialog(id);
}
basin
  • 3,949
  • 2
  • 27
  • 63

1 Answers1

1

5 years later I've got this issue. After hours of search and try, it seems that calling timePicker.clearFocus() will update the NumberPicker which is used internally by the TimePicker

Dario Coletto
  • 145
  • 3
  • 12