How do I set an Android TimePickerDialog
to use 15 minute intervals?
I need to create the picker programmatically as shown below so solutions involving a timepicker in XML (such as here: Android - TimePicker minutes to 15) will not work.
new TimePickerDialog(getActivity(), t, hour,minute, false).show();
The problem is that there appears to be no way to pass in a new function for TimePicker .setOnTimeChangedListener()
when the time picker is created.
Is it possible to use the new TimePIckerDialog constructor and use 15 minute intervals?
all relative answer need you to set an OnTimeChangedListener. My resolution is that you extends android TimePicker,and modify the constructor of it:
// minute
mMinuteSpinner = (NumberPicker) findViewById(R.id.minute);
mMinuteSpinner.setMinValue(0);
mMinuteSpinner.setMaxValue(3);
mMinuteSpinner.setDisplayedValues(new String[]{"0", "15", "30", "45"});
mMinuteSpinner.setOnLongPressUpdateInterval(100);
mMinuteSpinner.setFormatter(NumberPicker.getTwoDigitFormatter());
so you can have the interval you want.
Override the onTimeChanged method
TimePickerDialog timePickerDialog = new TimePickerDialog(this, listener, 1, 1, true) {
@Override
public void onTimeChanged(TimePicker view, int hourOfDay, int minute) {
...
}
};
timePickerDialog.show();
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With