Is it possible to disable specific dates in an Android datepicker?

I have a datepicker that turns off past dates.

For my application, for example, some events can only happen every Friday and Mondays every week. In this case, the user should only be able to select on Fridays and Mondays. Other dates must be disabled for selection. I do not want to check after selection.

Please let me know if possible.

date picker code:

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

    dpd = new DatePickerDialog(InfoActivity.this,
            new DatePickerDialog.OnDateSetListener() {

                @Override
                public void onDateSet(DatePicker view, int year,
                        int month, int dayOfMonth) {

                    month+=1;
                    String day = ""+dayOfMonth;
                    String mon = ""+ month;

                    try {
                        date=convertToINDateFormat(mon+"/"+day+"/"+year);
                    } catch (ParseException e) {
                        // TODO Auto-generated catch block
                        e.printStackTrace();
                    }
                }
            }, mYear, mMonth, mDay);
    dpd.setButton( DatePickerDialog.BUTTON_POSITIVE, "Set", new DialogInterface.OnClickListener()
    {
        @Override
        public void onClick( DialogInterface dialog, int which )
        {

           Intent i = new Intent(InfoActivity.this, ChooseSlot.class);
            startActivity(i);
            finish();

        }
    } );

      

... ,,,,,.

             Calendar c = Calendar.getInstance();
             c.add(Calendar.DATE, 1);
             Date newDate = c.getTime();
             dpd.getDatePicker().setMinDate(newDate.getTime());
             dpd.show();      

      

+3


source to share


2 answers


I think you can disable future dates with dpd.getDatePicker().setMaxDate(System.currentTimeMillis());

But not specific future dates



0


source


Visit fooobar.com/questions/721970 / ...   Better way and easy to understand ... if you are looking for how to disable a specified date this is better. not a loop. giving the exact date and cutting it off.



0


source







All Articles