私は Mono For Android を初めて使用し、1 つの入力テキスト データを activity1.cs の 1 つの 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 からテキストを取得していません。
ありがとう!