我正在编写一些自定义对话框,但我遇到了showDialog
方法的问题。出于某种原因,当我将想要创建的Dialog的id传递给showDialog
方法时,它会执行预期的大小写和默认大小写。
protected Dialog onCreateDialog(int id) {
switch (id) {
case DATE_DIALOG_ID:
Calendar c = Calendar.getInstance();
mYear = c.get(c.YEAR);
mMonth = c.get(c.MONTH);
mDay = c.get(c.DAY_OF_MONTH);
return new DatePickerDialog(this,
mDateSetListener,
mYear, mMonth, mDay);
default:
return null;
}
}
答案 0 :(得分:1)
break;
:
如果无法工作请参阅此http://www.vogella.de/articles/AndroidDialogs/article.html
答案 1 :(得分:1)
使用以下代码
更新您的代码DatePickerDialog dpd = null;
protected Dialog onCreateDialog(int id) {
switch (id) {
case DATE_DIALOG_ID:
Calendar c = Calendar.getInstance();
mYear = c.get(c.YEAR);
mMonth = c.get(c.MONTH);
mDay = c.get(c.DAY_OF_MONTH);
dpd = new DatePickerDialog(this, mDateSetListener, mYear, mMonth, mDay);
break; // you forgot this line in your code
default:
return null;
}
}