Updated to v1.5 with the following changes:
- Initializer now has a Scale parameter.
The default size of the picker is 84dip x 200dip, however if this is too big or too small you can specify a Scale (float) to resize it.
Example:
will result in a picker that is 126dip x 300dip.
Updated to v1.3 with the following changes:
- Time picker is now sized relative to the screen size (so it no longer looks tiny on a large screen);
- The "+" & "-" buttons now repeat when you long press on them - slowly at first, then faster.
Here's a real simple time picker library I wrote to address a need in a new project I'm working on. The class is CSTimePicker.
When you initialize it you pass it the activity you are calling it from & the view that will receive the result when the user taps the OK button. The view can be either a Label or an EditText & if you try to use anything else, you will get a toast message telling you to use either a Label or EditText.
You can provide an initial starting point for the time picker by putting a value in the receiving view & there is checking in there so that if the value isn't a valid time value, it will default to 09:00.
The hour & minute numbers will wrap in both directions & if you tap the down button for minutes when the time is say 10:00, it will become 09:59. Likewise, if you tap the minute up button when it's 09:59, it will become 10:00.
When the user taps the OK button, the timepicker value is returned to the receiving view as a string formatted as "##:##". If the user taps Cancel, it returns nothing.
There are 2 methods:
1) .Initialize(Activity, View, Scale) - Activity is the activity you are calling from & the view is the receiving EditText or Label;
2) .Show
An example piece of code would be:
It's pretty simple & not very colorful, but someone might find it useful.
- Colin.
- Initializer now has a Scale parameter.
The default size of the picker is 84dip x 200dip, however if this is too big or too small you can specify a Scale (float) to resize it.
Example:
B4X:
Private tp As CSTimePicker
tp.Initialize(Activity, txtApptTime, 1.5)
tp.Show
will result in a picker that is 126dip x 300dip.
Updated to v1.3 with the following changes:
- Time picker is now sized relative to the screen size (so it no longer looks tiny on a large screen);
- The "+" & "-" buttons now repeat when you long press on them - slowly at first, then faster.
Here's a real simple time picker library I wrote to address a need in a new project I'm working on. The class is CSTimePicker.
When you initialize it you pass it the activity you are calling it from & the view that will receive the result when the user taps the OK button. The view can be either a Label or an EditText & if you try to use anything else, you will get a toast message telling you to use either a Label or EditText.
You can provide an initial starting point for the time picker by putting a value in the receiving view & there is checking in there so that if the value isn't a valid time value, it will default to 09:00.
The hour & minute numbers will wrap in both directions & if you tap the down button for minutes when the time is say 10:00, it will become 09:59. Likewise, if you tap the minute up button when it's 09:59, it will become 10:00.
When the user taps the OK button, the timepicker value is returned to the receiving view as a string formatted as "##:##". If the user taps Cancel, it returns nothing.
There are 2 methods:
1) .Initialize(Activity, View, Scale) - Activity is the activity you are calling from & the view is the receiving EditText or Label;
2) .Show
An example piece of code would be:
B4X:
Sub ShowPicker_Click
Private tp as CSTimePicker
txtAppointmentTime.Text = "10:00"
tp.initialize(Activity, txtAppointmentTime, 1)
tp.Show
End Sub
It's pretty simple & not very colorful, but someone might find it useful.
- Colin.
Attachments
Last edited: