我正在尝试使用DatePicker / Calendar设置预订的开始和结束日期,并在textview中显示结果。到目前为止,输出只显示两次相同的日期,我错过了什么?假设我想设置从x date到y date的预约...我如何使用Calendar类设置它?
Plllleeeease指出我正确的方向!
由于
}
//Get an instance of Calendar and DateFormat class, and get current date from the system using OnClick method
Calendar startVacation = Calendar.getInstance();
Calendar endVacation = Calendar.getInstance();
DateFormat fmtDate = DateFormat.getDateInstance();
DateFormat fmtDateEnd = DateFormat.getDateInstance();
DatePickerDialog.OnDateSetListener startVaca = new DatePickerDialog.OnDateSetListener() {
@Override
public void onDateSet(DatePicker view, int year, int monthOfYear,
int dayOfMonth) {
// TODO Auto-generated method stub
startVacation.set(Calendar.YEAR, year);
startVacation.set(Calendar.MONTH, monthOfYear);
startVacation.set(Calendar.DAY_OF_MONTH, dayOfMonth);
}
};
DatePickerDialog.OnDateSetListener endVaca = new DatePickerDialog.OnDateSetListener() {
@Override
public void onDateSet(DatePicker view, int year, int monthOfYear,
int dayOfMonth) {
// TODO Auto-generated method stub
endVacation.set(Calendar.YEAR, year);
endVacation.set(Calendar.MONTH, monthOfYear);
endVacation.set(Calendar.DAY_OF_MONTH, dayOfMonth);
reservation.setText("You have reserved the " + cabinId + " starting on " + fmtDate.format(startVacation.getTime()) + " and ending on " + fmtDateEnd.format(endVacation.getTime()));
}
};
}