I am writing an application where the user needs to specify a given point in time, but i can't seem to figure out how to set the minute values that the user can choose from, to only use increments of 5 instead of increments of 1.
Simply put, when the user scrolls through the available amounts, he/she must only see 0,5,10,15 etc.
Thank you in advance.
After searching the net, I didn't find the simplest solution.
So I decided to share:
You can use reflections!
The following code use intervals of 10 minutes, but you can choose the minutes you want to use in the DISPLAYED_MINS array.
when you create your timepicker:
Just don't forget that getCurrentMinute() return the selected minute in the DISPLAY_MINS array. in order to get the minute:
You can do this programmatically.
Next, Set the
OnTimeChangedListener
as shown belowAnd,
To ensure you're compatible with API 21+, make sure your TimePicker has the following attribute:
Then here's how you can set an interval programmatically. This method falls back on the standard TimePicker if the minute field cannot be found:
all relative answer need you to set an OnTimeChangedListener. My resolution is that you extends android TimePicker,and modify the constructor of it:
so you can have the interval you want.
Thanks @Quaffffdd, this is the code in Kotlin