在我的程序中更新时,如果用户没有使用数据选择器将日期重新输入到 editText 框中(一个用于日期,另一个用于时间),则更新会将当前日期而不是旧日期插入到数据库中。我怎样才能让它保持旧时光?这是我用来输入日期和时间的代码 int 进入数据库
newTime.year = dateAndTime.get(Calendar.YEAR);
newTime.month = dateAndTime.get(Calendar.MONTH);
newTime.monthDay = dateAndTime.get(Calendar.DAY_OF_MONTH);
newTime.hour = dateAndTime.get(Calendar.HOUR_OF_DAY);
newTime.minute = dateAndTime.get(Calendar.MINUTE);
enteredTime = (int) ((newTime).toMillis(true) / 1000);
这是设置单击editText时的日期和时间的代码
public void date(View v) {
int inType = date.getInputType(); // backup the input type
date.setInputType(InputType.TYPE_NULL); // disable soft input
date.setInputType(inType);
new DatePickerDialog(report.this, d, dateAndTime.get(Calendar.YEAR),
dateAndTime.get(Calendar.MONTH),
dateAndTime.get(Calendar.DAY_OF_MONTH)).show();
}
public void time(View v) {
int inType = time.getInputType(); // backup the input type
time.setInputType(InputType.TYPE_NULL); // disable soft input
time.setInputType(inType);
new TimePickerDialog(report.this, t,
dateAndTime.get(Calendar.HOUR_OF_DAY),
dateAndTime.get(Calendar.MINUTE), true).show();
}
private void updateLabel() {
date.setText(fmtDate.format(dateAndTime.getTime()));
}
private void updateLabel1() {
time.setText(fmtTime.format(dateAndTime.getTime()));
}
DatePickerDialog.OnDateSetListener d = new DatePickerDialog.OnDateSetListener() {
public void onDateSet(DatePicker view, int year, int monthOfYear,
int dayOfMonth) {
dateAndTime.set(Calendar.YEAR, year);
dateAndTime.set(Calendar.MONTH, monthOfYear);
dateAndTime.set(Calendar.DAY_OF_MONTH, dayOfMonth);
updateLabel();
}
};
TimePickerDialog.OnTimeSetListener t = new TimePickerDialog.OnTimeSetListener() {
public void onTimeSet(TimePicker view, int hourOfDay, int minute) {
dateAndTime.set(Calendar.HOUR_OF_DAY, hourOfDay);
dateAndTime.set(Calendar.MINUTE, minute);
updateLabel1();
}
};