2014-01-21 74 views
0

默認情況下,活動的開始我希望顯示當前日期但明年。我添加了一個,但在啓動時的TextView中,我看到了當前的日期。感謝您的幫助。Android DatePicker下一年

public void chooseDate2(View v) { 
    new DatePickerDialog(Activity.this, d1, 
          dateAndTime1.get(Calendar.YEAR) + 1, 
         dateAndTime1.get(Calendar.MONTH), 
          dateAndTime1.get(Calendar.DAY_OF_MONTH)) 
     .show(); 
    } 
    private void updateLabel2() { 
    tv.setText(fmtDateAndTime.format(dateAndTime1.getTime()));   
    } 
    DatePickerDialog.OnDateSetListener d1=new DatePickerDialog.OnDateSetListener() { 
    public void onDateSet(DatePicker view, int year, int monthOfYear, int dayOfMonth) { 
     dateAndTime1.set(Calendar.YEAR, year); 
     dateAndTime1.set(Calendar.MONTH, monthOfYear); 
     dateAndTime1.set(Calendar.DAY_OF_MONTH, dayOfMonth); 
     updateLabel2(); 
    } 
    }; 

回答

4

使用

return new DatePickerDialog(this, datePickerListener, year+1, month, 
        day); 

private DatePickerDialog.OnDateSetListener datePickerListener = new DatePickerDialog.OnDateSetListener() { 
     public void onDateSet(DatePicker view, int selectedYear, 
       int selectedMonth, int selectedDay) { 
      year = selectedYear; 
      month = selectedMonth; 
      day = selectedDay; 
      datehere.setText(new StringBuilder().append(year).append("-") 
        .append(month + 1).append("-").append(day).append(" ")); 

     } 
    };