好吧,所以我刚刚切换了我的TimePickerDialog
to a TimePicker
由于客户需求,小部件在我正在处理的活动中直接可见。
问题是当我按所述上的任何箭头时TimePicker
,我得到一个 NullPointerException。
只是为了澄清,没有任何代码附加到TimePicker
除了这一行onCreate()
我的活动方法:
((TimePicker) findViewById(R.id.time_picker)).setIs24HourView(true);
I found 这个帖子 http://code.google.com/p/android/issues/detail?id=24387在谷歌论坛上关于这个问题,但没有太多帮助。
这是我的错误日志 http://pastebin.com/TB1NzK8j,遗憾的是我认为这不会有太大帮助。
仅在 ICS (Android 4.0 +) 中测试时才会出现此问题。有人能够解决这个问题吗?
刚刚编写了一个示例应用程序,在 Galaxy SIII (4.0) 中没有发现错误:
import android.app.Activity;
import android.os.Bundle;
import android.widget.TextView;
import android.widget.TimePicker;
import android.widget.TimePicker.OnTimeChangedListener;
public class TimePickerTestActivity extends Activity implements OnTimeChangedListener{
private TimePicker tpTime = null;
private TextView tvTime = null;
/** Called when the activity is first created. */
@Override
public void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.main);
tvTime = (TextView)this.findViewById(R.id.tv_time);
tpTime = (TimePicker)this.findViewById(R.id.tp_time);
tpTime.setIs24HourView(Boolean.TRUE);
tpTime.setOnTimeChangedListener(this);
}
public void onTimeChanged(TimePicker tp, final int hrOfDay, final int min) {
if(tp.equals(tpTime)){
tvTime.post(new Runnable(){
public void run() {
tvTime.setText(hrOfDay+":"+min);
}
});
}
}
}
以及布局 xml:
<?xml version="1.0" encoding="utf-8"?>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="fill_parent"
android:layout_height="fill_parent"
android:orientation="vertical" >
<TimePicker android:id="@+id/tp_time"
android:layout_width="fill_parent"
android:layout_height="wrap_content" />
<TextView android:id="@+id/tv_time"
android:layout_width="fill_parent"
android:layout_height="wrap_content" />
</LinearLayout>
FYI: http://developer.android.com/reference/android/widget/TimePicker.html http://developer.android.com/reference/android/widget/TimePicker.html
本文内容由网友自发贡献,版权归原作者所有,本站不承担相应法律责任。如您发现有涉嫌抄袭侵权的内容,请联系:hwhale#tublm.com(使用前将#替换为@)