如何在我的datePicker中设置minDate和maxDate我尝试将其置于onDateSet
内,但它不起作用。这是我的代码,也许你有其他方法。
显示datePIcker的按钮
etDueDate.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View view) {
Calendar c = Calendar.getInstance();
year = c.get(Calendar.YEAR);
month = c.get(Calendar.MONTH);
day = c.get(Calendar.DAY_OF_MONTH);
DatePickerDialog datePickerDialog = new DatePickerDialog(ownerAccept.this, ownerAccept.this,
year,month,day);
datePickerDialog.show();
}
});
datePicker
@Override
public void onDateSet(DatePicker datePicker, int i, int i1, int i2) {
yearFinal = i;
monthFinal = i1+1;
dayFinal = i2;
Calendar c = Calendar.getInstance();
hour = c.get(Calendar.HOUR_OF_DAY);
minute = c.get(Calendar.MINUTE);
TimePickerDialog timePickerDialog = new TimePickerDialog(ownerAccept.this, ownerAccept.this,
hour, minute, android.text.format.DateFormat.is24HourFormat(this));
timePickerDialog.show();
}
@Override
public void onTimeSet(TimePicker timePicker, int i, int i1) {
hourFinal = i;
minuteFinal = i1;
etDueDate.setText(yearFinal+"-"+monthFinal+"-"+dayFinal+" "+hourFinal+":"+minuteFinal+":00");
}
是的,在约会之后也有时间。 PLease帮助我们thaaanks :))
答案 0 :(得分:0)
您可以使用setMinDate()和setMaxDate()功能。
例如:
DatePickerDialog datePickerDialog = new DatePickerDialog(ownerAccept.this, ownerAccept.this,
year,month,day);
datePickerDialog.getDatePicker().setMaxDate(new Date().getTime());
datePickerDialog.show();