Question: How to limit on DatePicker to cannot choose date in future. I have DatePicker in activity which is used for registration. What to do so user cannot pick date of birthday if user has less that 18 years ( for example cannot pick date after today\_date - 18 years )?

Answer: 
I hope you got the answer till now. Following might be useful to others as well:
If you want to disable user to pick a date 18 years after today, here is what you may do.

Get time from 1-JAN-1970 to 18 years from now (in milli seconds)

```
   Calendar cal = Calendar.getInstance();
   cal.set(cal.get(Calendar.YEAR)+18,cal.get(Calendar.MONTH),cal.get(Calendar.DAY_OF_MONTH), 
            cal.get(Calendar.HOUR_OF_DAY), cal.get(Calendar.MINUTE), 0);
   long time = cal.getTimeInMillis();

```

set it as max allowed date in datepicker

```
   datepicker2.setMaxDate(time);

```

Hope it helps to anyone else looking for a answer
Count the year before 18 from now (current year) by int minYear = currentYear - 18; And then set that date with (Min year , current month, current day) as the max limit of the date picker.

```
    private static void setMaxLimitInDatePicker(DatePickerDialog datePickerDialog) {
    final Calendar calendar = Calendar.getInstance();

    int currentYear = calendar.get(Calendar.YEAR);
    int currentMonth = calendar.get(Calendar.MONTH);
    int currentDay = calendar.get(Calendar.DAY_OF_MONTH);

    int minYear = currentYear - 18;
    int minMonth = currentMonth;
    int minDay = currentDay;

    calendar.set(minYear, minMonth, minDay);
    long minDateInMilliSeconds = calendar.getTimeInMillis();

    // Set 18 years from today as max limit of date picker
    datePickerDialog.getDatePicker().setMaxDate(minDateInMilliSeconds);
}

```