PS: The solution used to work before this, but may be outdated now.
Try something like this. If I understand correctly, you want to set the minimum counter date to date. It works for me without any errors:
Calendar cal = Calendar.getInstance(); cal.set(cal.get(Calendar.YEAR), cal.get(Calendar.MONTH), cal.get(Calendar.DAY_OF_MONTH), 0, 0, 0); long time = cal.getTimeInMillis(); DatePicker datepicker = (DatePicker) findViewById(R.id.datePicker); datepicker.setMinDate(time);
In your xml, I assume you have something like this:
<DatePicker android:id="@+id/datePicker" android:layout_width="wrap_content" android:layout_height="wrap_content" />
source share