2011-05-24 117 views

回答

19

你應該能夠調用getDatePicker()。您的DatePickerDialog上的setMaxDate(long)將今天設置爲最大日期。您可以使用您發佈的代碼段中的相同名稱更新該功能。

請注意,DatePickerDialog是我在Android文檔中從我發佈的鏈接引用的對象。

@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: 
     //start changes... 
     DatePickerDialog dialog = new DatePickerDialog(this, mDateSetListener, cyear, cmonth, cday); 
     dialog.getDatePicker().setMaxDate(new Date().getTime()); 
     return dialog; 
     //end changes... 
    } 
    return null; 
} 
+0

謝謝尼古拉斯,請你告訴我在哪裏可以把這段代碼運行起來?我的意思是我應該把這個功能放在哪個功能?我指的是我在問題中發佈的代碼。 – 2011-05-25 06:06:26

+0

我已經更新了我的答案。 – 2011-05-25 13:11:53

+4

Nicholas,getDatePicker()方法在API級別11中可用,但我的應用程序針對的是API 7+,有沒有什麼方法可以在API級別7中執行此操作? – 2011-05-26 06:46:34

相關問題