我是 Mono For Android 的新手,我试图将一个键入的文本数据从 activity1.cs 上的一个 EditText 发送到另一个活动中的 TextView,但它不起作用。这是代码:
这是 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));
};
}
这是另一个活动:
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;
}
其他活动上的 EditText 没有从 Activity1.cs 上的 EditText 获取文本
谢谢你!