-1

how can I set minDate and maxDate in my datePicker I tried puting it inside the onDateSet but it didn't work. Here is my code maybe you have other ways.

The button to show datePIcker

        etDueDate.setOnClickListener(new View.OnClickListener() {
        @Override
        public void onClick(View view) {
            Calendar c = Calendar.getInstance();

            year = c.get(Calendar.YEAR);
            month = c.get(Calendar.MONTH);
            day = c.get(Calendar.DAY_OF_MONTH);

            DatePickerDialog datePickerDialog = new DatePickerDialog(ownerAccept.this, ownerAccept.this,
                    year,month,day);
            datePickerDialog.show();
        }
    });

the datePicker

  @Override
        public void onDateSet(DatePicker datePicker, int i, int i1, int i2) {
            yearFinal = i;
            monthFinal = i1+1;
            dayFinal = i2;

            Calendar c = Calendar.getInstance();
            hour = c.get(Calendar.HOUR_OF_DAY);
            minute = c.get(Calendar.MINUTE);

            TimePickerDialog timePickerDialog = new TimePickerDialog(ownerAccept.this, ownerAccept.this,
                    hour, minute, android.text.format.DateFormat.is24HourFormat(this));
            timePickerDialog.show();
        }

        @Override
        public void onTimeSet(TimePicker timePicker, int i, int i1) {
            hourFinal = i;
            minuteFinal = i1;

            etDueDate.setText(yearFinal+"-"+monthFinal+"-"+dayFinal+" "+hourFinal+":"+minuteFinal+":00");
        }

And yes it also have time after the date. PLease help me guys thaaanks :)

  • 1
    possible duplicate http://stackoverflow.com/questions/40759664/set-mindate-and-maxdate-in-datepicker?rq=1 – Marija Milosevic Jan 26 '17 at 15:30
  • 2
    Possible duplicate of [How set maximum date in datepicker dialog in android?](http://stackoverflow.com/questions/16749361/how-set-maximum-date-in-datepicker-dialog-in-android) – Abhishek Jain Jan 26 '17 at 15:31

1 Answers1

0

You can use setMinDate() and setMaxDate() function.

For example:

DatePickerDialog datePickerDialog = new DatePickerDialog(ownerAccept.this, ownerAccept.this,
                year,month,day);
datePickerDialog.getDatePicker().setMaxDate(new Date().getTime());
datePickerDialog.show();
Prerak Sola
  • 9,517
  • 7
  • 36
  • 67