我有一个项目,其中有两个按钮分别命名为from和todate。按下刷新按钮后,我需要根据开始日期和结束日期显示项目的状态。问题是我要选择日期,当我按日期和按日期时,它允许用户选择日期,并且日期应始终小于日期。
public void showDatePicker(final Button view1) {
// Get Current Date
final Calendar c = Calendar.getInstance();
mYear = c.get(Calendar.YEAR);
mMonth = c.get(Calendar.MONTH);
mDay = c.get(Calendar.DAY_OF_MONTH);
if (view1.getId() == R.id.to_date) {
if (fromDateData == null || "startfrom".equalsIgnoreCase(fromDateData) || fromDateData.isEmpty())
return;
final Calendar c = Calendar.getInstance();
String[] dates = fromDateData.split("-");
mYear = Integer.parseInt(dates[2]);
mMonth = Integer.parseInt(dates[1]) - 1;
mDay = Integer.parseInt(dates[0]);
c.set(Calendar.YEAR, mYear);
c.set(Calendar.MONTH, mMonth);
c.set(Calendar.DAY_OF_MONTH, mDay);
}
if (view1.getId() == R.id.to_date) {
if (fromDateData == null || "start from".equalsIgnoreCase(fromDateData) || fromDateData.isEmpty())
return;
final Calendar c = Calendar.getInstance();
String[] dates = fromDateData.split("-");
mYear = Integer.parseInt(dates[2]);
mMonth = Integer.parseInt(dates[1]) - 1;
mDay = Integer.parseInt(dates[0]);
c.set(Calendar.YEAR, mYear);
c.set(Calendar.MONTH, mMonth);
c.set(Calendar.DAY_OF_MONTH, mDay);
}
if (view1.getId() == R.id.from_date)
fromDateData=date;
else
toDateData = date;
view1.setText(date);
}
}, mYear, mMonth, mDay);
datePickerDialog.getDatePicker().setMaxDate(new Date().getTime());
if (view1.getId() != R.id.from_date)
datePickerDialog.getDatePicker().setMaxDate(c.getTimeInMillis()); datePickerDialog.getDatePicker().setMaxDate(new Date().getTime());
datePickerDialog.show();
}