这是我的显示对话框代码。
    @Override
    protected Dialog onCreateDialog(int id) {
    switch (id) {
    case 0:
        return new AlertDialog.Builder(this)
        .setIcon(R.drawable.ic_launcher)
        .setTitle("Select Reminder which you want to delete")
        .setPositiveButton("OK",
        new DialogInterface.OnClickListener() {
            public void onClick(DialogInterface dialog, int whichButton)
            {
                Toast.makeText(getBaseContext(), "OK clicked!", Toast.LENGTH_SHORT).show();
                check  = 1;
            }
        }
        )
        .setNegativeButton("Cancel",
        new DialogInterface.OnClickListener() {
            public void onClick(DialogInterface dialog, int whichButton)
            {
                Toast.makeText(getBaseContext(), "Cancel clicked!", Toast.LENGTH_SHORT).show();
                check = 2;
            }
        }
        )
        .setMultiChoiceItems(items, itemsChecked,
        new DialogInterface.OnMultiChoiceClickListener() {
            public void onClick(DialogInterface dialog,
                    int which, boolean isChecked) {
                Toast.makeText(getBaseContext(), items[which] + (isChecked ? " checked!":" unchecked!") + which, Toast.LENGTH_SHORT).show();
            }
        }
        ).create();
    }
        return null;
    }
这是我称之为的功能。
   public void show()
    {
        showDialog(0);
        if(check == 1)
        {
            Toast.makeText(this, "ok" + check, Toast.LENGTH_LONG).show();
        }
        else if (check == 2)
        {
            Toast.makeText(this, "Cancel" + check, Toast.LENGTH_LONG).show();
        }
    }
我面临着一些问题,我对“showDialog(0);”发生的事情感到困惑。功能运行良好,但是当我按下“ok”按钮时,对话框消失,它只显示用“ok”按钮的 onclicklistener 编写的 toast,但在“showDialog(0);”之后编写的代码 显示另一个 toast 就像无法访问,表示变量“check”(它是全局的),我在“ok”和“cancel”按钮的 onclicklisteners 中将其值设置为 1 或 2,并在“showDialog(0)之后在 if-else 条件下使用它们);" 显示不同的吐司,但功能“显示”结束而不检查 if-else 条件。我不明白这里到底发生了什么?