安卓TimePicker AM / PM按钮不调用onTimeChanged [英] Android TimePicker AM/PM button not invoking onTimeChanged
问题描述
我在实现我的应用程序中的TimePicker,它允许用户在一个数据库记录的时间而改变其插入之前的一些问题。
现在的问题是,当AM / PM按钮是pressed的onTimeChanged(查看,INT,INT)方法不会被调用。每当我改变任何一个小时或TimePicker的分值,onTimeChanged()被调用,但是。
方案:
- 用户只要点击了AM / PM按钮:AM / PM是不会更新
- 在用户点击时/分:时间被更新
- 在用户点击则AM / PM按钮可改变时/分:时间和AM / PM更新
我错在以为AM / PM按钮应该能够被点击更新时间而不具有AM / PM按钮后,也会改变一个时间值?
我已经把一个小的测试项目中复制此而这里的code:
活动
公共类TestActivity扩展活动实现OnTimeChangedListener {
私人日历mCalendar;
@覆盖
保护无效的onCreate(包savedInstanceState){
super.onCreate(savedInstanceState);
的setContentView(R.layout.timepicker);
mCalendar = Calendar.getInstance();
TimePicker TP =(TimePicker)findViewById(R.id.timepicker);
tp.setIs24HourView(假);
tp.setOnTimeChangedListener(本);
}
@覆盖
公共无效onTimeChanged(TimePicker观点,诠释hourOfDay,INT分钟){
Log.d(TAG,在onTimeChanged);
mCalendar.set(mCalendar.get(Calendar.YEAR)
mCalendar.get(Calendar.MONTH)
mCalendar.get(Calendar.DAY_OF_MONTH)
hourOfDay,
分钟);
setCalendarTime();
}
私人无效setCalendarTime(){
日期日期= mCalendar.getTime();
如果(日期!= NULL){
SimpleDateFormat的格式化=新的SimpleDateFormat(MM / DD / YY'@'H:毫米);
字符串日期时间= formatter.format(日期);
Toast.makeText(本,日期时间,Toast.LENGTH_LONG).show();
}
}
}
timepicker.xml
< LinearLayout中的xmlns:机器人=http://schemas.android.com/apk/res/android
机器人:layout_width =FILL_PARENT
机器人:layout_height =FILL_PARENT
机器人:fillViewport =真正的>
< TimePicker机器人:ID =@ + ID / timepicker
机器人:layout_width =FILL_PARENT
机器人:layout_height =WRAP_CONTENT
机器人:layout_marginLeft =5dip
机器人:layout_marginRight =5dip/>
< / LinearLayout中>
我已经测试code。是的,你说得对,TimePicker AM / PM按钮不调用onTimeChanged方法,它应该。
其实,它是一个错误。据报道,以谷歌。你可以在这里
找到它
HTTP://$c$c.google.com/p /安卓/问题/详细信息?ID = 18982
请投票,评论和放大器; 星的bug报告,以提高其优先级,并把它固定开发团队尽快。
I'm having some issues implementing a TimePicker in my application that allows the user to change the time of a database record prior to inserting it.
The problem is that when the AM/PM button is pressed, the onTimeChanged(View, int, int) method isn't invoked. Whenever I change either the hour or minute value of the TimePicker, onTimeChanged() is called, however.
Scenarios:
- User just clicks the AM/PM button: AM/PM is NOT updated
- User clicks the Hours/Minutes: Time is updated
- User clicks the AM/PM button then changes the hours/minutes: Time and AM/PM is updated
Am I wrong in thinking that the AM/PM button should be able to be clicked to update the time without having to also change a time value after the am/pm button?
I've put together a small test project to replicate this and here's the code:
Activity
public class TestActivity extends Activity implements OnTimeChangedListener {
private Calendar mCalendar;
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.timepicker);
mCalendar = Calendar.getInstance();
TimePicker tp = (TimePicker)findViewById(R.id.timepicker);
tp.setIs24HourView(false);
tp.setOnTimeChangedListener(this);
}
@Override
public void onTimeChanged(TimePicker view, int hourOfDay, int minute) {
Log.d("TAG", "In onTimeChanged");
mCalendar.set(mCalendar.get(Calendar.YEAR),
mCalendar.get(Calendar.MONTH),
mCalendar.get(Calendar.DAY_OF_MONTH),
hourOfDay,
minute);
setCalendarTime();
}
private void setCalendarTime() {
Date date = mCalendar.getTime();
if (date != null) {
SimpleDateFormat formatter = new SimpleDateFormat("MM/dd/yy '@' h:mm a");
String dateTime = formatter.format(date);
Toast.makeText(this, dateTime, Toast.LENGTH_LONG).show();
}
}
}
timepicker.xml
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="fill_parent"
android:layout_height="fill_parent"
android:fillViewport="true">
<TimePicker android:id="@+id/timepicker"
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:layout_marginLeft="5dip"
android:layout_marginRight="5dip"/>
</LinearLayout>
I have tested the code. Yes, you are right, TimePicker AM/PM button not invoking onTimeChanged method which it should.
Actually, Its a bug. It has been reported to google. You can find it here
http://code.google.com/p/android/issues/detail?id=18982
Please vote, comment & Star the bug report to raise its priority and to get it fixed by development team as soon as possible.
这篇关于安卓TimePicker AM / PM按钮不调用onTimeChanged的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!