monodroid中页面间传值
monodroid和java开发的差不多,直接贴代码,希望有帮助。
1、页面间跳转
![](https://images.cnblogs.com/OutliningIndicators/ContractedBlock.gif)
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
![](https://images.cnblogs.com/OutliningIndicators/ContractedBlock.gif)
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
![](https://images.cnblogs.com/OutliningIndicators/ContractedBlock.gif)
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();