2016-08-26 50 views
0

我是一名學生,我正在開發一個android預訂應用程序。在這些應用程序中,我有一個選擇日期的按鈕,當我點擊按鈕時,對話框出現選擇的日期,但我想禁止所有以前的日期,只想顯示的month.kindly幫助當前的日期和另外3個日期我怎麼能做到這一點感謝如何禁用日期選擇器對話框中的前幾個日期

pPickDate.setOnClickListener(new View.OnClickListener() { 
     public void onClick(View v) { 
      showDialog(DATE_DIALOG_ID); 
     } 
    }); 
    final Calendar cal = Calendar.getInstance(); 
    pYear = cal.get(Calendar.YEAR); 
    pMonth = cal.get(Calendar.MONTH); 
    pDay = cal.get(Calendar.DAY_OF_MONTH); 

    /** Display the current date in the TextView */ 
    updateDisplay(); 

} 
protected Dialog onCreateDialog(int id) { 
    switch (id) { 
     case DATE_DIALOG_ID: 
      return new DatePickerDialog(this, 
        pDateSetListener, 
        pYear, pMonth, pDay); 
    } 
    return null; 
} 

private void updateDisplay() { 
    pDisplayDate.setText(
      new StringBuilder() 
        // Month is 0 based so add 1 
        .append(pMonth + 1).append("/") 
        .append(pDay).append("/") 
        .append(pYear).append(" ")); 

} 

回答

0

試試這個

DatePickerDialog datePicker; 
private Calendar calendar; 
private int year, month, day; 
     // FETCH YEAR,MONTH,DAY FROM CALENDAR 
    calendar = Calendar.getInstance(); 
    year = calendar.get(Calendar.YEAR); 
    month = calendar.get(Calendar.MONTH); 
    day = calendar.get(Calendar.DAY_OF_MONTH); 

datePicker = new DatePickerDialog(this, YOUR_LISTENER, year, month, day); 
// this line is used for disable previous date but u can select the date 
datePicker.getDatePicker().setMinDate(System.currentTimeMillis()); 
// this line is used to prevent date selection 
datePicker.getDatePicker().setCalendarViewShown(false); 
相關問題