Android 上的 DatePicker 示例存在问题。可能是安卓系统的bug
我正在实现一个 DateTimePicker。我重复使用了这个存储库。
当我在更改分钟时尝试捕获 onTimeChanged()
方法的事件时,就会出现问题。如果我使用 + 和 – 按钮,就可以了,事件会被触发,我可以在这里处理它:
public void onTimeChanged(TimePicker view, int hourOfDay, int minute) {
// Update the internal Calendar instance
mCalendar.set(mCalendar.get(Calendar.YEAR),
mCalendar.get(Calendar.MONTH),
mCalendar.get(Calendar.DAY_OF_MONTH),
hourOfDay, minute);
}
而当我单击分钟并使用键盘事件不会出现,例如小时、天等...
问题的更详细描述是:
哪些步骤将重现该问题?
- 选择时间选择器
- 触摸 键盘就会出现
- 数字,所以当我写下几分钟时 ,事件没有触发
预期的输出是什么?您看到了什么?
我希望在 onTimeChanged()
中捕获此事件,但我不能。
您使用的产品版本是什么?在什么操作系统上?
版本 2。在 Android Froyo 上。
这段代码的作者告诉我 Android 上有一个错误。我认为应该解决这个问题,例如创建我自己的从 TimePicker 扩展的类并重新实现 OnTimeChangedListener 接口。
监听timerPicker事件的最佳选择是什么?
I am implementing a DateTimePicker. I have reuse this repository.
The problem appears when I am trying to catch the events for the onTimeChanged()
method when I change the minutes. If I use the buttons of + and – it's fine, the event is fired and I can handle it here:
public void onTimeChanged(TimePicker view, int hourOfDay, int minute) {
// Update the internal Calendar instance
mCalendar.set(mCalendar.get(Calendar.YEAR),
mCalendar.get(Calendar.MONTH),
mCalendar.get(Calendar.DAY_OF_MONTH),
hourOfDay, minute);
}
Whereas when I click on the minutes and I change it using the keyboard the event doesn't arise, as in the case of the hours, days, etc…
A more detail description of the problem is:
What steps will reproduce the problem?
- Select the time picker
- Touch on the numbers, so the keyboard appears
- when I write an amout of minutes, the event doesn't fire
What is the expected output? What do you see instead?
I would expect to catch this event inside onTimeChanged()
, but I cant.
What version of the product are you using? On what operating system?
Version 2. On Android Froyo.
The author of this code has told me there is a bug on Android. I think should be a work around to this problem, for example creating my own class extending from TimePicker and reimplementing the interface OnTimeChangedListener.
What is the best option to listen the timerPicker events?
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
DatePicker控件必须调用clearFocus()才能触发
onFocusChanged() 这将解决问题。
PFB 可能对您有帮助的链接:
http://code.google.com /p/android/issues/detail?id=2745
谢谢!
DatePicker control must call clearFocus() in order to trigger
onFocusChanged() and that will fix the issue.
PFB the link that might help you :
http://code.google.com/p/android/issues/detail?id=2745
Thanks!
该事件的触发方式与 HTML 中的
onchange
事件相同:它仅在离开文本框并转到下一个文本框后触发。
我无法判断这是否真的是一个错误或某种功能。
您可以捕获
KeyEvent。扩展
。然后,您应该了解TimePicker
类时的回调TimePicker
内部使用的EditText
控件内的每个按键。The event is fired in the same way as the
onchange
Event in HTML:It only fires after leaving the text boxes, and going to the next one.
I can't tell if it's really a bug or some kind of feature.
You could just catch the
KeyEvent.Callback
when extending theTimePicker
class. Then you should get informed about every single key press inside theEditText
controls internally used by theTimePicker
.