Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Disable Sundays and any other Specific Date

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.

like image 270
aenugula karthik Avatar asked Nov 25 '16 07:11

aenugula karthik


1 Answers

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.

like image 89
nick318 Avatar answered Nov 09 '22 23:11

nick318