I am trying Date Picker with this link but I'm not able to fix the issue regarding disabling past date selection in android
Asked
Active
Viewed 544 times
0
-
check this might help you http://stackoverflow.com/questions/17878751/how-to-disable-dates-before-today-date-in-datepickerdialog-android – Developer Dec 31 '15 at 07:12
-
go through this link ... http://stackoverflow.com/questions/32796326/still-able-to-select-disabled-dates-in-date-picker – MPG Dec 31 '15 at 10:33
1 Answers
1
Calendar c = Calendar.getInstance();
int mYear;
int mMonth;
int mDay;
mYear = c.get(Calendar.YEAR);
mMonth = c.get(Calendar.MONTH);
mDay = c.get(Calendar.DAY_OF_MONTH);
final DatePickerDialog datePickerDialog = new DatePickerDialog(this, new DatePickerDialog.OnDateSetListener() {
@Override
public void onDateSet(DatePicker view, int year, int monthOfYear, int dayOfMonth) {
String dateOfBirth1 = dayOfMonth + "-" + (monthOfYear + 1) + "-" + year;
dobButton.setText(dateOfBirth1);
}
}, mYear, mMonth, mDay);
Calendar minDate = Calendar.getInstance();
minDate.set(mYear1, mMonth1, mDay1);
datePickerDialog.getDatePicker().setMinDate(minDate.getTimeInMillis());

Rohit Heera
- 2,709
- 2
- 21
- 31
-
i have done the code for the disable date but if i select the disabled date from the calendar it should not selected so i am stuck on how to avoid selection of disable date.!! – Sidh Dec 31 '15 at 09:46
-
i am not getting you properly can you plz tell me your requirement – Rohit Heera Dec 31 '15 at 09:56
-
ok ..I have already share you the link above in my question.I am able to disable the past date but if i again select the past date like 30-12-2015.its getting selected in android lollipop 5.1 i want to disable the text also or you can say disable dates should not selected.!!!! – Sidh Dec 31 '15 at 09:59
-
Yes you try my code it will not displayed to you .Past date is not displayed – Rohit Heera Dec 31 '15 at 10:04
-
in your code minDate.set(mYear1, mMonth1, mDay1); where this argument comes inside the set method did you declared it globally?? – Sidh Dec 31 '15 at 10:15