0

I am using higher then API 11, here some problem during hide future date:

@Override
    protected Dialog onCreateDialog(int id) {
        Calendar c = Calendar.getInstance();
        int cyear = c.get(Calendar.YEAR);
        int cmonth = c.get(Calendar.MONTH);
        int cday = c.get(Calendar.DAY_OF_MONTH);
        switch (id) {
        case DATE_DIALOG_ID:
            DatePickerDialog dialog = new DatePickerDialog(this, mDateSetListener, cyear, cmonth, cday);
            dialog.getDatePicker().setMaxDate(new Date());
            return dialog;
            /*return new DatePickerDialog(this, mDateSetListener, cyear, cmonth,
                    cday);*/
        }
        return null;
    }

I have problem: setMaxDate(new Date());

I get this error:

The method setMaxDate(long) in the type DatePicker is not applicable for the arguments (Date)

So, Please how to hide future date .

2 Answers2

0

Well if you read the description of the method it says

public void setMaxDate (long maxDate) 
Added in API level 11
Sets the maximal date supported by this DatePicker in milliseconds since January 1, 1970 00:00:00 in getDefault() time zone.

Parameters
maxDate  The maximal supported date  

This means you can't just set a Date you have to convert your Date to a long value.

You can do it like this:

new Date().getTime()

More details here.

Community
  • 1
  • 1
OschtärEi
  • 2,255
  • 3
  • 20
  • 41
0

From the doc :

Sets the maximal date supported by this DatePicker in milliseconds since January 1, 1970 00:00:00 in getDefault() time zone.

You can do the following :

dialog.getDatePicker().setMaxDate(new Date().getTime());
Alexis C.
  • 91,686
  • 21
  • 171
  • 177