I want disable sundays and specific dates in particular months in android date picker
The Datepicker I used is android datepicker
:
Calendar calendar = Calendar.getInstance();
calendar.add(Calendar.MONTH, 1);
calendar.setMinimalDaysInFirstWeek(27);
// calendar.add(Calendar.DAY_OF_MONTH, 1);
//calendar.set(2016,11,23);
// new DatePickerDialog(LoginSuccess.this, listener, calendar.get(Calendar.YEAR), calendar.get(Calendar.MONTH), calendar.get(Calendar.DAY_OF_MONTH)).show();
DatePickerDialog dpDialog = new DatePickerDialog(LoginSuccess.this, listener, calendar.get(Calendar.YEAR), calendar.get(Calendar.MONTH), calendar.get(Calendar.DAY_OF_MONTH));
// dpDialog.updateDate(2016,11,23);
DatePicker datePicker = dpDialog.getDatePicker();
//datePicker.updateDate(2016,11,23);
// Date newDate = calendar.getTime();
//dpDialog.getDatePicker().setMinDate(newDate.getTime());
//datePicker.init();
if (calendar.get(Calendar.DAY_OF_MONTH)==Calendar.SUNDAY) {
// dpDialog.setTitle("Sorry Sundays wont be accepted");
// dpDialog.setMessage("not selected");
// dpDialog.show();
//datePicker.setBackgroundColor(000000);
Color.parseColor("#000000");
}
else {
long now = System.currentTimeMillis();
datePicker.setFirstDayOfWeek(Calendar.MONDAY);
datePicker.setMinDate(now + (1000 * 60 * 60 * 24 * 1));
datePicker.setMaxDate(calendar.getTimeInMillis());
dpDialog.show();
}
public DatePickerDialog.OnDateSetListener listener = new DatePickerDialog.OnDateSetListener() {
@Override
public void onDateSet(DatePicker view, int year, int monthOfYear, int dayOfMonth) {
Calendar calendar = Calendar.getInstance();
calendar.add(Calendar.MONTH, 1);
//calendar.set(2016,11,23);
display.setText("Selected Date:" + (dayOfMonth) + "/" + (monthOfYear + 1) + "/" + year);
Button ok = (Button) findViewById(R.id.confirm);
ok.setOnClickListener((v) -> {
Intent intent = new Intent(LoginSuccess.this, Confirm.class);
intent.putExtra("Date", dayOfMonth + "/" + (monthOfYear + 1) + "/" + year);
intent.putExtra("name", (String) spinnerOsversions.getSelectedItem());
intent.putExtra("email4", email3.toString());
intent.putExtra("bikeno4", bikeno3.toString());
intent.putExtra("fname", fname.toString());
//intent.putExtras(b);
startActivity(intent);
finish();
});
}
SetMinDate
and setMaxdate
is working Perfectly but I want to only disable sundays and particular days.
You can use https://github.com/wdullaer/MaterialDateTimePicker#additional-options
With the code below:datePicker.setSelectableDays(Calendar[] days)
And put all available days into datePicker.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With