1
我想在我的兩個選項卡活動中傳遞我主要活動的值。這裏是我的代碼:在選項卡之間傳遞值
主要活動:
public class MainActivity : TabActivity
{
protected override void OnCreate(Bundle bundle)
{
base.OnCreate(bundle);
// Set our view from the "main" layout resource
SetContentView(Resource.Layout.Main);
CreateTab(typeof(test1), "Page1", "Page1");
CreateTab(typeof(test2), "Page2", "Page2");
var test = new Intent(this, typeof(test1));
test.PutExtra("MyData", "Data from MainActivity");
var test = new Intent(this, typeof(test2));
test.PutExtra("MyData", "Data from MainActivity");
}
private void CreateTab(Type activityType, string tag, string label)
{
var intent = new Intent(this, activityType);
intent.AddFlags(ActivityFlags.NewTask);
var spec = TabHost.NewTabSpec(tag);
spec.SetIndicator(label);
spec.SetContent(intent);
TabHost.AddTab(spec);
}
}
而且在我的兩個活動,我想要這個:
TextView textview = new TextView(this);
textview.Text = Intent.GetStringExtra("MyData");
SetContentView(textview);
Unfortanetely我不採取任何結果。