我使用DatePickerDialog
下面的代码。我在我的数据库中检索用户的出生日期,当我打开dateDialog
它应该是用户的出生日期时。但是当它应该是九月时,它结束了十月。知道是什么原因造成的以及如何解决吗?
@Override
protected Dialog onCreateDialog(int id) {
switch (id) {
case DATE_DIALOG_ID:
return new DatePickerDialog(this,
mDateSetListener,
mYear, mMonth, mDay);
}
return null;
}
@Override
protected void onPrepareDialog(int id, Dialog dialog) {
switch (id) {
case DATE_DIALOG_ID:
((DatePickerDialog) dialog).updateDate(mYear, mMonth, mDay);
break;
}
}
private void updateDisplay() {
dateText.setText(
new StringBuilder()
// Month is 0 based so add 1
.append(mMonth +1).append("/")
.append(mDay).append("/")
.append(mYear).append(" "));
}
DatePickerDialog.OnDateSetListener mDateSetListener =
new DatePickerDialog.OnDateSetListener() {
@Override
public void onDateSet(DatePicker view, int year, int monthOfYear,
int dayOfMonth) {
mYear = year;
mMonth = monthOfYear;
mDay = dayOfMonth;
dob1 = (monthOfYear + "/" + dayOfMonth + "/" + year);
if(maxYear - mYear <= 12){
alertMessage = "User must be above age of 12.";
dialogBox();
year = mYear;
}
else{
updateDisplay();
}
}
};