确定工具的所有值是否不为空(Xamarin VS 2015 Android)

Identify if all the values of tools aren't null (Xamarin VS 2015 Android)

我的 android 应用程序中有以下工具。

  1. 编辑文本
  2. 旋转器
  3. ImageView

我还有一个按钮,如果你点击它,会出现一个对话框,告诉用户上面的所有工具是否都不为空。 (EditText有输入文字,Spinner有选值,ImageView有图片上传)

我想完成的是按钮应该如何确定所有这些工具都有值。

到目前为止,这是我的代码:

private void DialogBox(object sender, EventArgs eventArgs)
        {
            empName = FindViewById<EditText>(Resource.Id.editText1);
            request = FindViewById<EditText>(Resource.Id.editText3);
            phase = FindViewById<EditText>(Resource.Id.editText2);
            spinner1 = FindViewById<Spinner>(Resource.Id.spinner1);
            spinner2 = FindViewById<Spinner>(Resource.Id.spinner2);
            _imageView = FindViewById<ImageView>(Resource.Id.imageView1);

            if ((_imageView != null) && (empName.Text != null) && (request.Text != null) && (phase.Text != null) && (spinner1 != null) && (spinner2 != null))
            {
                Android.App.AlertDialog.Builder builder = new AlertDialog.Builder(this);
                AlertDialog alertDialog = builder.Create();
                alertDialog.SetTitle("Successful!");
                alertDialog.SetIcon(Android.Resource.Drawable.IcDialogInfo);
                alertDialog.SetMessage("Your request is successful.");
                alertDialog.SetButton("OK", (s, ev) =>
                {

                });
                alertDialog.Show();
            }
            else
            {
                Android.App.AlertDialog.Builder builder = new AlertDialog.Builder(this);
                AlertDialog alertDialog = builder.Create();
                alertDialog.SetTitle("Not successful!");
                alertDialog.SetIcon(Android.Resource.Drawable.IcDialogInfo);
                alertDialog.SetMessage("Please make sure you fill up all the information.");
                alertDialog.SetButton("OK", (s, ev) =>
                {

                });
                alertDialog.Show();
            }

        }

这里的问题是即使我没有输入任何东西,它总是给我成功的警报。

空文本框不一定为空。检查 "empty" 值的最佳方法是使用

String.IsNullOrEmpty(empName.Text)

如果你想检查 "not empty" 使用

!String.IsNullOrEmpty(empName.Text)

这些也是 String.IsNullOrWhiteSpace() 除了检查空值外还检查空白