0
我有兩個編輯文本框一個用於檢入和另一個用於檢出日期。設置一個DatePickerDialog分鐘日高於其他DatePickerDialog
我已經採取了兩個DatePickerDialog,它會打開時,你點擊編輯文本框,這是行之有效的,但我需要它來設置,所以當選擇一個日期檢查編輯文本框然後檢查out datepicker應該從入住日期的第二天開始。
即您的退房日期不能在您入住日期之前。
my current code:
private void setDateTimeField() {
checkInEdit.setOnFocusChangeListener(new View.OnFocusChangeListener() {
@Override
public void onFocusChange(View v, boolean hasFocus) {
if (hasFocus){
fromDatePickerDialog.show();
}
}
});
checkOutEdit.setOnFocusChangeListener(new View.OnFocusChangeListener() {
@Override
public void onFocusChange(View v, boolean hasFocus) {
if (hasFocus) {
toDatePickerDialog.show();
}
}
});
Calendar newCalendar = Calendar.getInstance();
fromDatePickerDialog = new DatePickerDialog(this, new DatePickerDialog.OnDateSetListener() {
public void onDateSet(DatePicker view, int year, int monthOfYear, int dayOfMonth) {
Calendar newDate = Calendar.getInstance();
newDate.set(year, monthOfYear, dayOfMonth);
checkInEdit.setText(dayOfMonth + "-" + monthOfYear + "-" + year);
newDate.add(Calendar.DATE, 1);
toDatePickerDialog.getDatePicker().setMinDate(newDate.get(Calendar.MILLISECOND));
}
},newCalendar.get(Calendar.YEAR), newCalendar.get(Calendar.MONTH), newCalendar.get(Calendar.DAY_OF_MONTH));
toDatePickerDialog = new DatePickerDialog(this, new DatePickerDialog.OnDateSetListener() {
public void onDateSet(DatePicker view, int year, int monthOfYear, int dayOfMonth) {
Calendar newDate = Calendar.getInstance();
newDate.set(year, monthOfYear, dayOfMonth);
checkOutEdit.setText(dayOfMonth + "-" + monthOfYear + "-" + year);
}
},newCalendar.get(Calendar.YEAR), newCalendar.get(Calendar.MONTH), newCalendar.get(Calendar.DAY_OF_MONTH));
fromDatePickerDialog.getDatePicker().setMinDate(newCalendar.get(Calendar.MILLISECOND));
toDatePickerDialog.getDatePicker().setMinDate(newCalendar.get(Calendar.MILLISECOND));
}
我添加了這行
toDatePickerDialog.getDatePicker().setMinDate(newDate.get(Calendar.MILLISECOND));
在
fromDatePickerDialog
onDateSet方法
,然而,這似乎並不堅持,即當我打開toDatePickerDialog它的日期仍設置爲今天。