警报对话框未显示

本文关键字:显示 对话框 | 更新日期: 2023-09-27 18:19:29

我有一个解析器,它将一个值作为字符串获取,如果它不等于预期值,则调用下面的函数。只有下面的函数什么也不做,它到达builder.show(),然后跳回我的解析器。它不显示对话框,因为如果显示对话框,当选择"确定"按钮时,它会在代理上点击finish()。任何可能导致这个问题的想法。我不知道我是否有一些语法不正常,或者问题是什么?我感谢所有的帮助。

private void errorReturnReader(string val)
    {
        string message = "";
        if (val != "")
        {
            AlertDialog.Builder builder;
            builder = new AlertDialog.Builder (this,3);
            builder.SetTitle("Institution Status Error");
            builder.SetCancelable(false);
            builder.SetPositiveButton("OK", delegate { Finish(); });
            switch (val)
            {
            case "NO_KEY":
                message = "The Key passed does not exist.";
                break;
            case "NO_EMP":
                message = "The employee id does not exist in the specified institution.";
                break;
            case "NO_INST":
                message = "The Institution code associated with key does not exist.";
                break;
            case "NO_BRANCH":
                message = "The Branch value passed does not exist.";
                break;
            case "EMP_EXCL":
                message = "Employee is excluded from all branches.";
                break;
            case "NO_STAT":
                message = "No audit records were found for the branch.";
                break;
            case "NO_RESPONSE":
                message = "No status was returned";
                break;
            case "NO_COMM":
                message = "The Cloud has not communicated with the Console within 60 seconds. Can not verify status.";
                break;
            default:
                break;
            }
            builder.SetMessage(message);
            builder.Create ();
            builder.Show ();
        }
    }

警报对话框未显示

对于字符串比较,请使用.equals(),即。更改

 if (val != "")

 if (!"".equals(val))

 if (val.length() != 0)

有关更多信息,请参阅如何比较Java中的字符串?

同时显示对话框,更改

 builder.Create ();
 builder.Show ();

 builder.create().show();

有关更多信息,请参阅Android警报对话框示例