从另一个EditText输入值Visual Studio C #Android设置EditText值

时间:2017-07-11 08:14:50

标签: c# android visual-studio android-edittext xamarin.android

我有一个按钮和两个edittext字段。当我单击按钮时,我希望将edittext1的文本值设置为edittext2的文本值。我该怎么做?

我想要这样的事情:

button1.Click += (sender, e) =>{
string s = editText1.Text.ToString();
editText2.Text = s;
};

我现在拥有的东西:

public class MainActivity : Activity
{
    Button button1;
    EditText editText1;
    EditText editText2;

    protected override void OnCreate(Bundle bundle)
    {
        base.OnCreate(bundle);
        SetContentView(Resource.Layout.Main);

        button1 = FindViewById<Button>(Resource.Id.button1);
        EditText editText1 = FindViewById<EditText>(Resource.Id.EditText1);
        EditText editText2 = FindViewById<EditText>(Resource.Id.EditText2);

            button1.Click += (sender, e) =>
            {
                string value = editText1.Text.ToString();
//On the next line of code
//Unhandled Exception:
//System.NullReferenceException: Object reference not set to an instance of an object.
                editText2.Text = value;
            };
    }
}

0 个答案:

没有答案