Is their a way to disable Datepicker
swiping for past month?
I came across to this link, and this . But it seems it will not disable the swiping / going back to previous month.
Reason : Setting a task in the present / future days.
Is their a way to disable Datepicker
swiping for past month?
I came across to this link, and this . But it seems it will not disable the swiping / going back to previous month.
Reason : Setting a task in the present / future days.
You may create your own DatePickerDialog class. Then pass necessary date in milli currents when calling datePicker. setMinDate()
method will disable previous days and swipe will also be disabled.
DatePickerDialog class:
public class myDatePickerDialogFragment extends DialogFragment {
int mDay, mMonth, mYear;
long current;
// you also need to pass OnDateSetListener that is implemented in
// activity which is calling this datePicker
OnDateSetListener onSetDate;
public myDatePickerDialogFragment(){
}
@Override
public void setArguments(Bundle args) {
super.setArguments(args);
mDay = args.getInt("day");
mMonth = args.getInt("month");
mYear = args.getInt("year");
current = args.getLong("minDate");
}
public void setOnDateSetListener(OnDateSetListener setDate){
onSetDate = setDate;
}
@Override
public Dialog onCreateDialog(Bundle savedInstanceState) {
DatePickerDialog datePickerDialog = new DatePickerDialog(getActivity(), onSetDate, mYear, mMonth, mDay);
// here you set minimum day. User cannot chose earlier dates.
datePickerDialog.getDatePicker().setMinDate(current);
return datePickerDialog;
}
}
Inside of Activity:
Bundle args = new Bundle();
args.putInt("day", mDay);
args.putInt("month", mMonth);
args.putInt("year", mYear);
args.putLong("minDate", yourCalendarObject.getTimeInMillis());
myDatePickerDialogFragment dialog = new myDatePickerDialogFragment();
dialog.setArguments(args);
dialog.setOnDateSetListener(datePickerListener);
dialog.show(getSupportFragmentManager(), "date");
OnDateSetListener:
DatePickerDialog.OnDateSetListener datePickerListener = new DatePickerDialog.OnDateSetListener() {
@Override
public void onDateSet(DatePicker view, int year, int monthOfYear, int dayOfMonth) {
// do other work after date is set here
}
};