EKN EKN - 1 month ago 17
Android Question

Display issue with TimePicker: Only current time is selectable

I want to display a

TimePicker
with all time slot is available to select. But for me only the time slots after the current time is available to select.

Please check my code.

final Calendar now = Calendar.getInstance();
TimePickerDialog timePickerDialog = new TimePickerDialog();
timePickerDialog.initialize(new TimePickerDialog.OnTimeSetListener() {
@Override
public void onTimeSet(RadialPickerLayout view, int hourOfDay, int minute, int second) {
now.set(Calendar.HOUR_OF_DAY, 0);
now.set(Calendar.MINUTE, 0);
now.set(Calendar.SECOND, 0);
SimpleDateFormat simpleDateFormat = new SimpleDateFormat("hh:mm a");
String selectedDateString = simpleDateFormat.format(now.getTime());


tvTimePicker.setText(selectedDateString);


}
}, now.get(Calendar.HOUR_OF_DAY), now.get(Calendar.MINUTE), now.get(Calendar.SECOND), false);

Calendar minNowCalendar = Calendar.getInstance();
timePickerDialog.setMinTime(minNowCalendar.get(Calendar.HOUR_OF_DAY), minNowCalendar.get(Calendar.MINUTE), minNowCalendar.get(Calendar.SECOND));


timePickerDialog.show(getActivity().getFragmentManager(),"Key");

Answer

Remove this line:

timePickerDialog.setMinTime(minNowCalendar.get(Calendar.HOUR_OF_DAY), minNowCalendar.get(Calendar.MINUTE), minNowCalendar.get(Calendar.SECOND));