如何在 TimePickerDialog 中禁用分钟更改
只允许更改营业时间,怎么办?
在简单的TimePicker中,我可以设置TimePicker.OnTimeChangedListener接口,但该接口在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.
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(3)
您可以复制原始 Widget 的源代码及其布局,并将其作为“库”类包含在您自己的项目中。您还需要更新源对 R 的引用。通过布局,您可以显示任何您想要的内容,但会议记录不可编辑。由于这是家庭作业,请务必正确注意您正在从 Android 源库自定义小部件。
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.
使用 getCurrentHour() 和 setCurrentHour(),并将分钟设置为 0。
Use getCurrentHour() and setCurrentHour(), and set the minutes to 0.
文档没有显示任何方法来做到这一点,所以我想没有这样的方法。您可以对 TimePicker 类进行子类化并自行禁用分钟选择器,但没有理由做这么多工作。
但是,您可以将该值设置为 0 (
TimePicker.setCurrentMinute(0)
),如果用户更改它,则忽略即可。并且您应该告知用户更改分钟并不重要,因为您不使用它。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.