我是Android编程的新手,当我在logcat中打印日期时,正确的日期即将到来,但是当在editText中显示时,月份的意外值即将到来。 比如当我选择1月份时,月份的价值将变为31。 这是我的代码:
private void setDateTimeField()
{
e2.setOnFocusChangeListener(this);
Calendar newCalendar = Calendar.getInstance();
datePickerDialog = new DatePickerDialog(this, new OnDateSetListener()
{
public void onDateSet(DatePicker view, int year, int monthOfYear, int dayOfMonth)
{
Calendar newDate = Calendar.getInstance();
//Log.e("Date",newDate+"");
newDate.set(year, monthOfYear+1, dayOfMonth);
Log.e("Year:",year+"/month:"+(monthOfYear+1)+"/date:"+dayOfMonth);
Log.e("Date:",newDate+"");
e2.setText(dateFormat.format(newDate.getTime()));
}
},newCalendar.get(Calendar.YEAR),(newCalendar.get(Calendar.MONTH)),
newCalendar.get(Calendar.DAY_OF_MONTH));
}
@Override
public void onFocusChange(View arg0, boolean arg1) {
if(arg0 == e2)
{
datePickerDialog.show();
}
}