如果使用键盘我如何捕获一个TimePicker当时间的变化? [英] How can I capture when time changes in a TimePicker if the keyboard is being used?
问题描述
我有一个小窗口是一个TimePicker检索保存在一个场中的数据库所需的时间。
I have a widget which is a TimePicker that retrieves the time saved in a field in a database.
的是,当用户改变在插件的时间值,这是不被保存在数据库中。
Thing is that when the user changes the time value in the widget, this is not being saved in the database.
所以,我遇到了 setOnTimeChangedListener 方法用得好好的,如果你只使用加号和减号的小部件。如果您使用的是关键字它并没有捕捉到变化。
So I came across the setOnTimeChangedListener method that works like a charm, if you are only using the plus and minus signs in the widget. It does not capture the change if you are using the keyword.
下面是我的code:
pickedTime.setOnTimeChangedListener(new TimePicker.OnTimeChangedListener() {
public void onTimeChanged(TimePicker arg0, int arg1, int arg2) {
System.out.println("What time is it? "
+ String.valueOf(arg0.getCurrentHour()) + ":"
+ String.valueOf(arg0.getCurrentMinute()));
}
});
我也没能成功:
I've also tried unsuccessfully:
pickedTime.setOnFocusChangeListener 和 pickedTime.setOnKeyListener 的方法。
推荐答案
由于mon3t发现,该选项是设置机器人:XML文件中AddStatesFromChildren =真,如:
As mon3t found out, the option is to set android:AddStatesFromChildren="true" in the XML file, as:
<DatePicker
android:id="@+id/datePicker"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:addStatesFromChildren="true" />
<TimePicker
android:id="@+id/timePicker"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:addStatesFromChildren="true" />
也可以设置通过code:
Or you can set that by code:
datePicker.setAddStatesFromChildren(true);
timePicker.setAddStatesFromChildren(true);
我实在不明白什么是默认的一点是现在这个样子。
I really cannot understand what is the point of the default being the way it is.
这篇关于如果使用键盘我如何捕获一个TimePicker当时间的变化?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!