0

目標は、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);

        };
};
4

1 に答える 1

1

これにより強制終了が発生することはありませんが、次の値を設定しようとするとメニューが表示されます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;
}
于 2012-06-17T22:44:26.217 に答える