intent = new Intent(this.Activity, typeof(TabFragment2));
甲Fragment是一塊AP的可以將放置在活動中,但不應使用此方法打開Fragment
。
打開TabFragment2
這樣的:
var fragment = new TabFragment2();
// Execute a transaction, replacing any existing fragment with this one inside the frame.
var fragmentTransaction = FragmentManager.BeginTransaction();
fragmentTransaction.Replace(Resource.Id.fragment, fragment);
fragmentTransaction.Commit();
有關的信息,你可以閱讀document,這裏是一個example;當您打開Fragment2
:
I want to pass data between two fragments.
當您使用fragmentTransaction.Replace
方法來打開你的TabFragment2
,你可以傳遞數據這樣
Fragment2 fragment = new Fragment2();
Bundle args = new Bundle();
args.PutString("param", myip.Text);
args.PutInt("paramInt", 12);
fragment.Arguments = args;
在Fragment2,從Arguments
得到的數據:
public override View OnCreateView(LayoutInflater inflater, ViewGroup container, Bundle savedInstanceState)
{
View view = LayoutInflater.From(Activity).Inflate(Resource.Layout.fragment2, null);
if (Arguments != null)
{
String mParam1 = Arguments.GetString("param");
int mParam2 = Arguments.GetInt("paramInt");
}
}
什麼是錯誤?看起來你在第一個片段上有一個拼寫錯誤,在那裏你說'mytrack'而不是'mytracks'(最後一行)。 – hankide
@hankide System.ArgumentNullException:值不能爲空。 參數名稱:String >>>> int mytracks = int.Parse(Activity.Intent.GetStringExtra(「MyData1」)); – controleng
https://developer.xamarin.com/guides/android/platform_features/fragments/fragments_walkthrough/part_1_-_walkthrough/ –