How can I establish, for example, that the user can only choose between 6:00 AM and 6:00 PM in one TimePickerDialog
and that the other hours are disabled if they are not in the range in this case from 6:01 PM to 5 :59 AM would be disabled for selection, this is myTimePickerDialog
TimePickerDialog recogerHora = new TimePickerDialog(getContext(), (view12, hourOfDay, minute) -> {
String horaFormateada = (hourOfDay < 10) ? CERO + hourOfDay : String.valueOf(hourOfDay);
String minutoFormateado = (minute < 10) ? CERO + minute : String.valueOf(minute);
String AM_PM;
if(hourOfDay < 12) {
AM_PM = "a.m.";
} else {
AM_PM = "p.m.";
}
horaET.setText(horaFormateada + DOS_PUNTOS + minutoFormateado + " " + AM_PM);
}, horaClock, minutoClock, false);
recogerHora.show();
I have investigated about it but I can't find anything that can help me, I hope you can help me, thank you very much in advance!
To set the minimum and maximum time in
TimePickerDialog
, as in aDatePickerDialog
, you must do it in the listener that detects the change in this caseOnTimeSetListener
.In the case of
TimePickerDialog
hours, they cannot be disabled (you can use this MaterialDateTimePicker library as an option but you can perform the validation.Set the minimum and maximum allowed times and compare them to the selected time using the after() and before() functions .