I am new to Mono For Android and im trying to send one typed-text data from one EditText on activity1.cs to a TextView in another activity, but it doesnt work.
Here is the code:
this is the Activity1.cs:
public string Item;
protected override void OnCreate(Bundle bundle)
{
base.OnCreate(bundle);
// Set our view from the "main" layout resource
SetContentView(Resource.Layout.Main);
// Get our button from the layout resource,
// and attach an event to it
Button AddButton = FindViewById<Button>(Resource.Id.AddButton);
Button ViewButton = FindViewById<Button>(Resource.Id.ViewButton);
EditText addNewAssignmentField = FindViewById<EditText>(Resource.Id.addNewAssignmentField);
AddButton.Click += delegate
{
if (addNewAssignmentField.Text == "")
{
Toast.MakeText(this, "Please Write Assignment To Add", ToastLength.Short).Show();
}
else
{
Item = addNewAssignmentField.Text;//.ToString();
Toast.MakeText(this, "Assignment Added!", ToastLength.Short).Show();
addNewAssignmentField.Text = "";
ShowMessage(Item); //ignore this
}
};
ViewButton.Click += delegate
{
StartActivity(typeof(ViewListActivity));
};
}
This is the other activity:
Activity1 ac1 = new Activity1();
protected override void OnCreate(Bundle bundle)
{
base.OnCreate(bundle);
// Set our view from the "ListLayout" layout resource
SetContentView(Resource.Layout.ListLayout);
Button button1 = FindViewById<Button>(Resource.Id.button1);
var listItemsTxt = new TextView(this);
EditText itemsList = FindViewById<EditText>(Resource.Id.itemsList);
itemsList.Text = ac1.Item;
}
the EditText on the other activity isnt getting the text from the EditText on the Activity1.cs
Thank You!
You should pass it through intents
In your first activity
In your second activity’s
onCreate