I want to customise the default TimePicker of android.widget. I want to show only the minutes options and hide the Hours and AM/PM options. I was able to hide AM/PM option by using the following code :
TimePicker refreshRate= (TimePicker)findViewById(R.id.refreshRate);
refreshRate.setIs24HourView(true);
Can anyone tell me how to hide the hours option as I only want to use the Minute option?
The documentation of TimePicker does not mention any method or constructor to hide the hour counter. The TimePicker consists basically of two NumberPickers, so for the use of only picking minutes we have to use a NumberPicker with the following option:
minuteNumberPicker.setMinValue(0);
minuteNumberPicker.setMaxValue(59);
Related
I'm creating a appointment booking app in android studio.
So while selecting time in time picker i want the time between 14:00pm and 16:00pm to be disabled ,similarly - the timing at night must be disabled.
&
While selecting Date , I want the previous dates to be disabled.
is it possible?
You would have to use a custom TimePickerDialog in this case, same goes to the date as well if you would need that functionality too.
See this post - Custom TimePickerDialog or use this library - MaterialDateTimePicker with material design.
I have a project where I use datepicker for the user to confirm a date
When the user selects confirm I wish to disable the datepicker so that they can't use it again
Unfortunatelly when I do something like this:
((DatePicker)findViewById(R.id.datepicker)).enabled = false;
only the spinner part gets disabled while the calendar can still be touched and used to alter the spinner
the only solution I found is using setCalendarViewShown(false) when the user confirms and then disabling the picker
unfortunatelly this seems to be deprecated so I wish to find some way to replace it
So my question is this
Is there a way to programmatically either disable ALL parts of the DatePicker or hide the calendar?
I know it can be done through xml but I wish to use it in code
Thanks in advance for any help you can provide
You can hide the datepicker with:
datepicker.setVisibility(View.INVISIBLE);
An option that you can choose to disabled all dates less one, is combine this two lines.
datepicker.setMinDate
datepicker.setMaxDate
So after the user pick one date, set the date like the min and the max of the calendar, and with this way, the user will not be able to choose a new one.
Something like:
datepicker.setMinDate(theDatePickedByUser)
datepicker.setMaxDate(theDatePickedByUser)
It should work...
Android's new DatePicker widget shows a large date text at the top, but I really don't need it. It's wasting a lot of space. Is there a way to hide that, and show only the calendar below.
Just use CalendarView, which does not show the header and has all the same methods.
I'm creating an app which will have a countdown timer.
I would like to choose the time by TimePicker (after clicking a button).
I would like to have only a few choices. It is 15,30,45 minutes.
Unfortunately TimePicker is not exactly what I wanted.
Is there any possibility to edit TimePicker, to show only a custom set of values?
Thanks in advance!
Rather than showing a TimePicker for choosing 15, 30 or 45 minutes, you should use a Spinner
If you don't know how to use a spinner tell me in the comment!
It is possible to do that using reflection. I am not sure if it is a right thing to do though.
Here's an example of how it could be done. Line 60 replaces the 24-hour spinner with 12 Japanese symbols in android earlier than 3.0. Lines 74-76 do the same for 3.0+.
It might be better to create your own dialog with spinners, but for my code I wanted to mimic the native TimePicker.
I need to create a custom time picker that includes seconds. Is there a generic control in Android that can be used for each of the input controls (hours, minutes and seconds)? It would look and function like the TimePicker with the +/- buttons.
There's an opensource Time picker with second.
Otherwise you should create your own datepicker, by using the Time-class and three NumberPickers.