SpeedBirdNine
SpeedBirdNine

Reputation: 4676

How to disable minutes change in TimePickerDialog

Is need to allow only to change hours, how can it be done?

In simple TimePicker, i can set the TimePicker.OnTimeChangedListener interface, but this interface is not available in TimePickerDialog.

Upvotes: 2

Views: 3692

Answers (3)

Dan S
Dan S

Reputation: 9189

You can copy the source of the original Widget and its layout and include it in your own project as a "library" class. You will also need to update the source's references to R. With the layout you can show anything you'd like in regards to not having minutes being editable. Since this is homework be sure to correctly note that you're customizing widget from Android source library.

Upvotes: 1

Jong
Jong

Reputation: 9115

The documentation doesn't show any way to do that, so I guess there is no such a way. You could subclass the TimePicker class and disable the minute picker yourself, somehow, but there is no reason to work so much.

However, you can set the value to 0 (TimePicker.setCurrentMinute(0)) and if the user changes it, just ignore. And you should inform the user that changing the minute doesn't matter, as you don't use it.

Upvotes: 0

Sergio
Sergio

Reputation: 655

Use getCurrentHour() and setCurrentHour(), and set the minutes to 0.

Upvotes: 1

Related Questions