1

我是 android 的新手并且有以下问题:这是代码:

 base.OnCreate(bundle);
        var layout = FindViewById<LinearLayout>(Resource.Id.layout1);
        Button butondata = FindViewById<Button>(Resource.Id.button3);
        Button butonstartdate = FindViewById<Button>(Resource.Id.button4);
        Button butonenddate = FindViewById<Button>(Resource.Id.button5);
        EditText txtsubiect = FindViewById<EditText>(Resource.Id.editText1);
        Button submit = FindViewById<Button>(Resource.Id.buttonsalveaza);

        butondata.Click += butondata_Click;

        submit.Click += (sender, e) =>
            {
                txtsubiect.TextChanged += (object sender1, Android.Text.TextChangedEventArgs f) =>
                    {


                        if (txtsubiect.Text.Length <= 0)
                        {
                            txtsubiect.RequestFocus();
                            txtsubiect.SetError("Eroare,camp gol!");
                        }
                    };
            };

当我构建它时,它说:方法'SetError'没有重载需要1个参数,有什么问题,因为我有点困惑,错误消息会出现吗?谢谢!

4

1 回答 1

1

您需要设置一个可绘制对象以与错误消息一起显示。它需要 2 个参数,第二个是 Drawable,一个与消息一起显示的图标。

Drawable icon_error = Resources.GetDrawable(Resource.Drawable.icon_error);//this should be your error image.
icon_error.SetBounds(0,0,icon_error.IntrinsicWidth,icon_error.IntrinsicHeight);

if (txtsubiect.Text.Length <= 0)
                        {
                            txtsubiect.RequestFocus();
                            txtsubiect.SetError("Eroare,camp gol!", icon_error );
                        }
于 2014-08-15T17:17:55.413 回答