全部。从我的变量更新 DatePicker 的值时我遇到了一些问题。
所以,首先我做了什么 - 创建 DatePicker 并从中获取 Date
final DatePicker newDatePicker = (DatePicker)view.findViewById(R.id.dpResult);
final Calendar c = Calendar.getInstance();
final int year = c.get(Calendar.YEAR);
final int month = c.get(Calendar.MONTH);
final int day = c.get(Calendar.DAY_OF_MONTH);
newDatePicker.init(year, month, day, null);
newDatePicker.setMinDate(System.currentTimeMillis() - 1000);
builder.setPositiveButton("OK", new DialogInterface.OnClickListener() {
public void onClick(DialogInterface dialog, int which) {
@SuppressWarnings("deprecation")
Date date = new Date(newDatePicker.getYear()-1900,
newDatePicker.getMonth(),
newDatePicker.getDayOfMonth());
//hear is some list where I add the date field
dealList.add(new ItemDeal(newDescription.getText().toString(), date,
false));
((BaseAdapter)listView.getAdapter()).notifyDataSetChanged();
}
然后,当我想编辑一些信息时,我希望 DatePicker 显示该字段的日期。所以我尝试使用 DatePicker.updateDate():
final DatePicker newDatePicker = (DatePicker)view.findViewById(R.id.dpResult);
Date itemDate = (Date)c.dealList.get(numberOfItem).getDealTime();
//newDatePicker.init(itemDate.getYear(), itemDate.getMonth(), itemDate.getMonth(), null);
newDatePicker.updateDate(itemDate.getYear(), itemDate.getMonth(), itemDate.getMonth());
当我这样做时,DatePicker 显示 1900 年 1 月 1 日。通过调试器,我看到了 itemDate - 它有日期。请帮忙。我做错了什么?