警报对话框未显示

时间:2014-08-27 05:36:11

标签: c# android alertdialog android-alertdialog

我有一个解析器,它将值作为字符串抓取,如果它不等于预期值,则调用下面的函数。只有下面的函数什么都不做,它会进入builder.show(),然后跳回我的解析器。它没有显示对话框,因为如果它确实如此,那么当选择Ok按钮时它会点击委托上的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 ();
        }
    }

1 个答案:

答案 0 :(得分: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