Disable specific dates of day in Android date picker

前端 未结 5 1526
日久生厌
日久生厌 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:42

    That is not possible with the android datepicker and you need to create a custom picker for yourself. See MaterialDateTimePicker

    To disable Sundays you have to pass the array like this

          GregorianCalendar g1=new GregorianCalendar();
          g1.add(Calendar.DATE, 1);
          GregorianCalendar gc = new GregorianCalendar();
          gc.add(Calendar.DAY_OF_MONTH, 30);
           List dayslist= new LinkedList();
    Calendar[] daysArray;
    Calendar cAux = Calendar.getInstance();
    while ( cAux.getTimeInMillis() <= gc.getTimeInMillis()) {
        if (cAux.get(Calendar.DAY_OF_WEEK) != 1) {
            Calendar c = Calendar.getInstance();
            c.setTimeInMillis(cAux.getTimeInMillis());
            dayslist.add(c);
        }
        cAux.setTimeInMillis(cAux.getTimeInMillis() + (24*60*60*1000));
    }
    daysArray = new Calendar[dayslist.size()];
    for (int i = 0; i

提交回复
热议问题