[英]Android: Dialog force closes on create
目标是使出现在menu_key上的对话框被按下,但保持强制关闭。 我查阅了有关Dialogs的官方常见问题解答 ,但没有运气。 一切都按照此处的说明进行,但是一旦按下按钮仍然失败。 这是对话框的创建:
static final int Choice_ID = 0;
protected Dialog onCreateDialog(int id) {
Dialog dialog = null;
switch(id) {
case Choice_ID:
// do the work to define the pause Dialog
AlertDialog.Builder builder = new AlertDialog.Builder(this);
builder.setMessage("TEST DIALOG")
.setCancelable(true);
AlertDialog alert = builder.create();
break;
//default:
//dialog = null;
}
return dialog;
}
关于显示的部分如下所示:
public boolean onKeyDown(int keyCode, KeyEvent event) {
if (keyCode == KeyEvent.KEYCODE_MENU) {
showDialog(Choice_ID);
};
};
这不会导致强制关闭,但是如果您尝试设置dialog
的值,则可以看到菜单:
dialog = builder.create();
如:
protected Dialog onCreateDialog(int id) {
Dialog dialog = null;
switch(id) {
case Choice_ID:
// do the work to define the pause Dialog
AlertDialog.Builder builder = new AlertDialog.Builder(this);
builder.setMessage("TEST DIALOG")
.setCancelable(true);
dialog = builder.create();
break;
//default:
//dialog = null;
}
return dialog;
}
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.