monodroid开发之--页面间传值
monodroid和java在开发android应用程序的差不多。贴点代码希望有对研究monodroid的兄弟帮助。
1、页面间跳转
Button btn_showOtherActivity = FindViewById<Button>(Resource.id.Activity1_btnShow);
btn_showOtherActivity += (o, e) =>
{
Intent my_showItem = new Intent();
my_showItem.SetClass(this, typeof(Activity2));
this.StartActivityForResult(my_showItem, 0);
};
Button btn_myClose= FindViewById<Button>(Resource.id.Activity1_btnClose);
btn_myClose+= (o, e) =>
{
this.Finish();
};
btn_showOtherActivity += (o, e) =>
{
Intent my_showItem = new Intent();
my_showItem.SetClass(this, typeof(Activity2));
this.StartActivityForResult(my_showItem, 0);
};
Button btn_myClose= FindViewById<Button>(Resource.id.Activity1_btnClose);
btn_myClose+= (o, e) =>
{
this.Finish();
};
2、页面传值
Activity1.cs
ISharedPreferences sharedPreferences = GetSharedPreferences("my_share_item", FileCreationMode.Private);
ISharedPreferencesEditor spEditor = sharedPreferences.Edit();
spEditor.PutString("item1", "value1|value2|value3|value4");
spEditor.Commit();
ISharedPreferencesEditor spEditor = sharedPreferences.Edit();
spEditor.PutString("item1", "value1|value2|value3|value4");
spEditor.Commit();
Activity2.cs
ISharedPreferences sharedPreferences = GetSharedPreferences("my_share_item", FileCreationMode.Private);
ISharedPreferencesEditor spEditor = sharedPreferences.Edit();
string[] valArr = sharedPreferences.GetString("item1", string.Empty).Split('|');
sharedPreferences.Edit().Clear();
sharedPreferences.Edit().Commit();
ISharedPreferencesEditor spEditor = sharedPreferences.Edit();
string[] valArr = sharedPreferences.GetString("item1", string.Empty).Split('|');
sharedPreferences.Edit().Clear();
sharedPreferences.Edit().Commit();