Set TimePickerDialog to use 15 minute intervals

How to configure Android TimePickerDialog to use 15 minute intervals?

I need to create the collector programmatically, as shown below, so XML timer related solutions (for example, here: Android - TimePicker up to 15 minutes ) will not work.

 new TimePickerDialog(getActivity(), t, hour,minute, false).show(); 

The problem is that when creating a timer, there is no way to pass a new function to TimePicker .setOnTimeChangedListener() .

Can I use the new TimePIckerDialog constructor and use 15-minute intervals?

+3
source share
3 answers

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(); 
+2
source

for all relative answers you need to set OnTimeChangedListener. My solution is that you extend android TimePicker and change its constructor:

 // 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 that you can have the desired interval.

+1
source

Gathering partial solutions from this and other posts, I believe that the solution here captures all the fields for displaying TimePickerDialog with a custom minute step displayed in NumberPicker .

0
source

Source: https://habr.com/ru/post/982062/


All Articles