由于Android不支持显示日期,我在我的布局中添加了TextView.
在DatePicker上我放了一个onDateChangedListener.当日期改变时,我确定星期几,然后通过处理程序设置它以确保它在UI线程上完成:
// this is being called when the date changes on the DatePicker
public void onDateChanged(DatePicker view, final int year,
final int monthOfYear, final int dayOfMonth) {
String dayOfTheWeek = null;
// some code here to set the 'dayOfTheWeek' string
h.sendMessage(h.obtainMessage(0, dayOfTheWeek));
}
final Handler h = new Handler() {
@Override
public void handleMessage(Message msg) {
dayOfWeekTextView.setText((String)msg.obj);
}
};
我的问题:当我滚动窗口小部件(Android 4.0 UI)中的日子时,它不顺畅!我检查问题是什么,这不是我确定String应该是什么的方式,它实际上是Handler中的setText().评论那部分uit,一切都很好.同时在那里设置硬编码文本(dayOfWeekTextView.setText(“SOMETHING”);)会产生同样的问题.它会抖动DatePicker.
setText()真的是一个很大的动作吗?奇妙清单显示了星期几,并且运行平稳,但我无法知道他们是如何做到的.
我只在HTC One X上测试过它.
有人有想法吗?
Edit:
I found out why it is smooth in Wunderlist! I am using the same as them, a DialogFragment. You can set a title on the dialog and that is what Wunderlist uses instead of a TextView. So I’m going to use that (and looks better too