@Override
protected Dialog onCreateDialog(int id) {
switch (id) {
case IDD_COLOR:
return new AlertDialog(this); // The constructor AlertDialog(context) is not visible
}
return null;
}
为什么?怎么了?AlertDialog不起作用
@Override
protected Dialog onCreateDialog(int id) {
switch (id) {
case IDD_COLOR:
return new AlertDialog(this); // The constructor AlertDialog(context) is not visible
}
return null;
}
为什么?怎么了?AlertDialog不起作用
构造函数AlertDialog(Context context)
是protected
,只对同一包中的类,子类和类都可见。
请参阅此链接了解如何创建一个AlertDialog
:
不能创建一个AlertDialog
因为它有一个受保护的构造,可以通过使用AlertDialog.Builder
使AlertDialog
的。
More information关于该主题。
请使用AlertDialog.Builder
,如:
AlertDialog.Builder builder = new AlertDialog.Builder(a)
.setCustomTitle(buildAlertTitle(a, title, 18))
.setMultiChoiceItems(choices, checkedChoices, multiChoiceClickListener)
.setPositiveButton(okButtonLabel, okButtonClickListener)
.setNegativeButton(cancelButtonLabel, cancelButtonClickListener);
AlertDialog alert = builder.create(); // create one
alert.show(); //display it
欲了解更多信息,请使用谷歌的 “Android AlertDialog.Builder样本”
BR 肖恩
True..Thanks ... – Jim 2011-02-05 15:53:38