How to customize the TimePicker? - android

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.

Related

Using android timepicker as a number picker

My general problem is that I need to set a preference with a number from a finite list using something like a step size of 10 (or whatever). I know I can do this with the classic NumberPicker but I like the look of the TimePicker and was wondering if anyone has some idea of how to customize it to act as a more of a general number picker. It's probably fine with 12 values but it would be even better if you could have an arbitrary number of choices. Maybe there's a different widget that would get me something similar...
Here's a crude mockup of a dialog example
see How to create a number picker dialog?
you could set the timepicker to 24h format and get 1-24 range. But I wouldn't recommend it. The Bottom line is you pretty much need to design the xml and java class for your custom number picker.

How to enable setCalendarViewShown or disable calendar in datepicker post API 24

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 date pick field following guidelines

Following Android's design guidelines, I ran into this part https://developer.android.com/design/style/metrics-grids.html, where they use a view that I believe is a Spinner in order to show and possibly select the date.
Please guide me in the right directions as I'm not 100% sure this is a Spinner, and also, checking the Calendar app, it seems once you click on it, a DialogFragment pops up, with a single DatePicker (or TimePicker for the hours), but I am not 100% sure of this either.
Thanks in advance
Take a look at the docs, you can specify the Spinner mode. Whether you choose to make it a dialog or dropdown is up to you. Either way, you don't have to worry about setting the value after user has selected it.
http://developer.android.com/reference/android/widget/Spinner.html#MODE_DIALOG

Show only Minute scroller of TimePicker in Android

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);

Time picker in android

HI Every One. I am new to android Developmemt . Actually my project requires to show Timepicker but i doesnot want to show AM or PM option and also not in the header of the picker, There is any way to do this ?
Please reply ASAP
You can remove the AM/PM selector using the setIs24HourView(true) method of TimePicker. I've not tried it myself, but I think this should also remove the AM/PM caption from the header.
Hope that helps, bye

Categories

Resources