Disable specific dates of day in Android date picker

前端 未结 5 1524
日久生厌
日久生厌 2020-12-06 05:06

I\'m using the datePicker and I can disable last days of today and later days after 30 days by the following code:

DatePickerDialog datePicker = new DatePick         


        
5条回答
  •  失恋的感觉
    2020-12-06 05:50

    Visit https://stackoverflow.com/a/44692231/6631959 Best method and easy to understand... if u are searching for how to disable a specified date it is better. not a looping procedure. giving any exact date and disabling it.

    The code is HEre::

    SimpleDateFormat sdf = new SimpleDateFormat("dd-MM-yyyy");
                        String a = "26-07-2017";
                        java.util.Date date = null;
                        try {
                            date = sdf.parse(a);
                            MainActivity obj = new MainActivity();
                            calendar = obj.dateToCalendar(date);
                            System.out.println(calendar.getTime());
                        } catch (ParseException e) {
                            e.printStackTrace();
                        }
    
                        List dates = new ArrayList<>();
                        dates.add(calendar);
                        Calendar[] disabledDays1 = dates.toArray(new Calendar[dates.size()]);
                        dpd.setDisabledDays(disabledDays1);
        private Calendar dateToCalendar(Date date) {
                Calendar calendar = Calendar.getInstance();
                calendar.setTime(date);
                return calendar;
            }
    

提交回复
热议问题