我有一个非常简单的日期选择器片段:
public class DatePickerFragment extends DialogFragment implements
OnDateSetListener {
@Override
public Dialog onCreateDialog(Bundle savedInstanceState) {
final Calendar c = Calendar.getInstance();
int year = c.get(Calendar.YEAR);
int month = c.get(Calendar.MONTH);
int day = c.get(Calendar.DAY_OF_MONTH);
return new DatePickerDialog(getActivity(), this, year, month, day);
}
@Override
public void onDateSet(DatePicker view, int year, int month, int day) {
Activity a = getActivity();
Button dateDueButton = (Button) a.findViewById(R.id.dateDue);
String sYear = Integer.toString(year).substring(2, 4);
String sMonth = Integer.toString(month + 1);
String sDay = Integer.toString(day);
dateDueButton.setText(sMonth + "/" + sDay + "/" + sYear);
}
}
我希望能够设置“日期边界”。例如,如果当前日期是 2 月 9 日,我希望仅在 2 月 10 日或之后的日期显示在片段上。我该如何实施呢?