2016-04-26 124 views
0
DatePickerDialog dpd= new DatePickerDialog(this, pDateSetListener, pYear, pMonth, pDay); 
DatePickerDialog da = new DatePickerDialog(this, pDateSetListener, pYear, pMonth, pDay); 
Calendar c = Calendar.getInstance(); 
c.add(Calendar.DATE, 1); 
Date newDate = c.getTime(); 
dpd.getDatePicker().setMinDate(newDate.getTime()); 
dpd.getDatePicker().setMaxDate(date+(1000*60*60*24*60)); 
return dpd; 

我在哪裏錯了,因爲這不起作用,請幫助。設置日期選擇器的最大日期

+0

什麼是'da'?什麼是'日期'?使用'dpd.getDatePicker()。setMaxDate(newDate.getTime()+(1000 * 60 * 60 * 24 * 60));'我會說。並刪除unrelevent代碼。 – shkschneider

+0

它爲我工作後,我把1000L而不是1000 –

回答

0

這個工作對我來說嘗試

private void handelDate(){ 
    if(minDate!=null){ 
     Calendar min= Calendar.getInstance(); 
     min.setTime(minDate); 
     min.set(Calendar.HOUR_OF_DAY, min.getMinimum(Calendar.HOUR_OF_DAY)); 
     min.set(Calendar.MINUTE, min.getMinimum(Calendar.MINUTE)); 
     min.set(Calendar.SECOND, min.getMinimum(Calendar.SECOND)); 
     min.set(Calendar.MILLISECOND, min.getMinimum(Calendar.MILLISECOND)); 

     CalendarView cv = datePicker.getCalendarView(); // should check for null 
     long cur = cv.getDate(); 
     int d = cv.getFirstDayOfWeek(); 
     try { 
      datePicker.setMinDate(min.getTimeInMillis()); 
     } catch (Exception e) { 
      e.printStackTrace(); 
     } 
     cv.setDate(cur + 1000L*60*60*24*40); 
     cv.setFirstDayOfWeek((d + 1) % 7); 
     cv.setDate(cur); 
     cv.setFirstDayOfWeek(d); 
    } 
    if(maxDate!=null){ 
     datePicker.setMaxDate(maxDate.getTime()); 
    } 

} 
+0

它做到了,謝謝你太多了 –

相關問題