Artem
Artem

Reputation: 4639

Can't set current day on DatePickerDialog

This is my code:

DatePickerDialog dialog = new DatePickerDialog(OtherEventActivity.this, R.style.DatePickerDialogTheme,
    new DateSetListener(), mYear, (mMonth), mDay);
try {
      dialog.getDatePicker().setMaxDate(System.currentTimeMillis());
} catch (Exception e) {}

dialog.show();

When I start app I can't press on the current day on Android 5 (higher or below works good).

UPD - I tried this too:

dialog.getDatePicker().setMaxDate(new Date().getTime());

Upvotes: 0

Views: 105

Answers (1)

Ragesh Ramesh
Ragesh Ramesh

Reputation: 3520

There is a bug in android 5. The date picker does not allow you to pick current date if you set max date as today. The workaround i used was

if (Build.VERSION.SDK_INT == Build.VERSION_CODES.LOLLIPOP)
      dialog.getDatePicker().setMaxDate(System.currentTimeMillis() +  TimeUnit.DAYS.toMillis(24));
else
     dialog.getDatePicker().setMaxDate(System.currentTimeMillis());

Its not a perfect solution but it works.

Upvotes: 2

Related Questions