Disable chosen date in Datepickerdialog

Asked

Viewed 403 times

0

Hello, everybody, all right? I wonder if it is possible, through the Datepickerdialog, to disable dates that users have chosen? Like, users choose a datepicker date that can no longer appear to other users, like in hair salons, which can’t have the same spot for two people. I got to the part of creating the Datepickerdialog, however, I do not know how to disable these dates after chosen by users.

 diaAgendamento= (TextView) findViewById(R.id.textViewDataInicial);
    diaAgendamento.setOnClickListener(new View.OnClickListener() {
        @Override
        public void onClick(View v) {
            Calendar calendar = Calendar.getInstance();
            int dia = calendar.get(Calendar.DAY_OF_MONTH);
            int mes = calendar.get(Calendar.MONTH);
            int ano = calendar.get(Calendar.YEAR);

            DatePickerDialog dialog = new DatePickerDialog(MainActivity.this, android.R.style.Theme_Holo_Dialog_MinWidth, datePicker, dia, mes, ano);
            dialog.show();
        }
    });
    datePicker = new DatePickerDialog.OnDateSetListener() {
        @Override
        public void onDateSet(DatePicker view, int year, int month, int dayOfMonth) {
            month = month + 1;
            String date = dayOfMonth + "/" + month + "/" + year;
            diaAgendamento.setText(date);
        }
    };

1 answer

1

Try to use this library Material Date Time Picker, on it you can set an option to show specific dates.

Example

datePicker.setSelectableDays(Calendar[] days)

Passing a array of Calendar as a parameter that contains all the dates that can be selected.

  • Maybe it’s easier to use setDisabledDays(Calendar[] days)

  • Thank you for your response. I have only one question: I’m putting Compile 'com.wdullaer:materialdatetimepicker:3.4.1' in my build.Radle and yet.

Browser other questions tagged

You are not signed in. Login or sign up in order to post.