我使用這個鏈接Date Picker設定分鐘日期在日期選擇器使用對話框片段
我知道我們可以用setMinDate()方法設定最低日期創建我的日期選擇器創建的,但我不明白怎麼做如果我們按照鏈接中提供的方式執行日期選擇器。 我沒有找到任何使用此方法的方法。 日期選擇器代碼
public static class DatePickerFragment extends DialogFragment
implements DatePickerDialog.OnDateSetListener {
@NonNull
@Override
public Dialog onCreateDialog(Bundle savedInstanceState) {
// Use the current date as the default date in the picker
tv_date= (TextView)getActivity().findViewById(R.id.tv_date);
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);
// Create a new instance of DatePickerDialog and return it
return new DatePickerDialog(getActivity(), this, year, month, day);
}
public void onDateSet(DatePicker view, int year, int month, int day) {
// Do something with the date chosen by the user
tv_date.setText(new StringBuilder().append(day).append("-")
.append(month+1).append("-").append(year));
date=tv_date.getText().toString();
}
}
http://stackoverflow.com/questions/16749361/how-set-maximum-date-in-datepicker-dialog-in-android – Raghunandan
@Raghunandan首先檢查鏈接我提供。實現方式與我的情況不同 –
Look @ http://developer.android.com/reference/android/app/DatePickerDialog.html#getDatePicker()。在onCreateDialog中,你返回一個日期選擇器對話框 – Raghunandan