I have a button, and two edittext fields. When I click the button I want the text value of edittext1 to be set as the text value of edittext2. How do I do this?
I want something like this:
button1.Click += (sender, e) =>{
string s = editText1.Text.ToString();
editText2.Text = s;
};
What I have right now:
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;
};
}
}