【问题标题】:Alert Dialog Not Displaying不显示警报对话框
【发布时间】:2014-08-27 05:36:10
【问题描述】:

我有一个解析器,它将一个值作为字符串抓取,如果它不等于预期值,则调用以下函数。只有下面的函数什么都不做,它到达 builder.show() 然后跳回我的解析器。它没有显示对话框,因为如果选择了OK按钮时它会在委托时击中委托()。关于可能导致此问题的任何想法。我不知道我是否有一些语法错误或问题是什么?我感谢任何和所有的帮助。

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 ();
        }
    }

【问题讨论】:

  • 试试这个:builder.Create().show();
  • 我在发布之前也尝试过,它并没有改变结果。感谢您的回复。

标签: c# android android-alertdialog


【解决方案1】:

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

 if (val != "")

 if (!"".equals(val))

 if (val.length() != 0)

欲了解更多信息,请参阅How do I compare strings in Java?

还有显示对话框,改变

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

 builder.create().show();

欲了解更多信息,请参阅Android Alert Dialog Example

【讨论】:

    猜你喜欢
    • 2020-01-14
    • 1970-01-01
    • 2023-03-13
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多