目標は、menu_keyが押されたときに表示されるダイアログを作成することですが、強制的に閉じ続けます。Dialogsに関する公式FAQを調べましたが、うまくいきませんでした。ここで説明されているようにすべてが実行されましたが、ボタンを押すとすぐに失敗します。ダイアログの作成は次のとおりです。
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);
};
};