我在编辑文本上应用以下代码来选择日期。
public class DatePickerFragment extends DialogFragment
{
private OnDateSetListener listener;
public DatePickerFragment(OnDateSetListener listener)
{
this.listener = listener;
}
@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(), listener, year, month, day);
}
}
@Override
public void onDateSet(DatePicker view, int year, int monthOfYear, int dayOfMonth)
{
//do some stuff
}
void showDateDialog()
{
DatePickerFragment newFragment = new DatePickerFragment(this);
newFragment.show(getFragmentManager(), "date_picker");
}
但是,我想将所有过去的日期变灰,以便不允许用户选择其中任何一个。这可以通过代码实现吗?或者我应该在选择后手动检查日期是否为过去日期?