我目前的问题是从 DatePickerDialog 获得的值在我将它们发送到 Date 构造函数时没有得到正确解析。
获取日期值(根据另一篇文章的建议)....
private DatePickerDialog.OnDateSetListener listener = new DatePickerDialog.OnDateSetListener() {
@Override
public void onDateSet(DatePicker view, int year, int monthOfYear,
int dayOfMonth) {
mYear = year;
mMonth = monthOfYear + 1;
mDayOfMonth = dayOfMonth;
String t = "listener => mYear=" + mYear + "; mMonth=" + mMonth +
"; mDayOfMonth=" + mDayOfMonth + ";";
Log.i(TAG, t);
}
};
上面的日志语句产生:
04-30 21:34:10.548: I/TodosActivity(29510): listener => mYear=2012; mMonth=5; mDayOfMonth=2;
日期是用......
todo.setDueDate(new Date(mYear, mMonth, mDayOfMonth));
我验证了到期日......
String t = "setNewDueDate(Todo) => #" + todo.getId() + ": " + todo.getTitle() + " (" +
todo.getText() + "). Created on " + format.format(todo.getCreatedDate()) +
". Last modified on " + format.format(todo.getModifiedDate()) +
". Due on " + format.format(todo.getDueDate()) + ".";
Log.i(TAG, t);
这导致....
04-30 21:34:05.703: I/TodosActivity(29510): setNewDueDate(Todo) => #1: Test (Test). Created on 30 Apr 2012 20:07:51. Last modified on 30 Apr 2012 20:55:27. Due on 31 Dec 1899 00:00:00.
编辑:
设置初始 DatePickerDialog 值...
return new DatePickerDialog(this, listener, cal.get(Calendar.YEAR),
cal.get(Calendar.MONTH), cal.get(Calendar.DAY_OF_MONTH));
有什么我应该/不应该做的事吗?