1

I have tried to much but nothing works for me can anybody help me how to disable certain dates in calender here is my code but its just hiding past dates.

         final Calendar c = Calendar.getInstance();
            mYear = c.get(Calendar.YEAR);
            mMonth = c.get(Calendar.MONTH);
            mDay = c.get(Calendar.DAY_OF_MONTH);


            DatePickerDialog datePickerDialog = new DatePickerDialog(MoreDetail.this,
                    new DatePickerDialog.OnDateSetListener() {

                        @Override
                        public void onDateSet(DatePicker view, int year,
                                              int monthOfYear, int dayOfMonth) {
                            String s = dayOfMonth + "" + "-" + monthOfYear + 1 + "" + "-" + year + "";
                        }
                    }, mYear, mMonth, mDay);
            Calendar minDate = Calendar.getInstance();
            minDate.set(mYear, mMonth, mDay);
            datePickerDialog.getDatePicker().setMinDate(minDate.getTimeInMillis());
            datePickerDialog.show();
Innocent
  • 703
  • 10
  • 21
  • You can't disable certain dates - you can only set range(min/max)... but this one `String s = dayOfMonth + "" + "-" + monthOfYear + 1 + "" + "-" + year + "";` is [great](http://ideone.com/Gjharc) – Selvin Nov 29 '16 at 11:02
  • 1
    @Innocent: Check this -> http://stackoverflow.com/a/34730506/4018207 – AndiGeeky Nov 29 '16 at 11:04
  • As of now what you can do is that create a list of dates which are supposed to be disable. After the user selects the date check that date is in list of disabled date or not. If it is in the list of disable date make a error toast and show up the calendar again. – Rahul Sharma Nov 29 '16 at 11:08
  • @AndiGeeky any more libraries you know please suggest me – Innocent Nov 29 '16 at 11:24
  • @Innocent: Check this also-> https://github.com/square/android-times-square – AndiGeeky Nov 29 '16 at 11:26

1 Answers1

2

Please check this GitHub repo for CustomDatePicker.

https://github.com/wdullaer/MaterialDateTimePicker

setDisabledDays(Calendar[] days)

The values in this Calendar[] are explicitly disabled (not selectable). This option can be used together with setSelectableDays(Calendar[] days): in case there is a clash setDisabledDays(Calendar[] days) will take precedence over setSelectableDays(Calendar[] days)

Thanks.

AndiGeeky
  • 11,266
  • 6
  • 50
  • 66