我是新來的Mono For Android,我試圖從一個Activity1.cs上的EditText發送一個類型化文本數據到另一個Activity中的TextView,但它不起作用。 下面是代碼:從一個活動發送EditText數據到其他
這是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上的其他活動獲得心不是從的EditText文本在Activity1.cs上
謝謝!
我不知道單聲道,但它的方式是通過意圖,所以我建議你谷歌「機器人單聲道意圖」 – Budius