当数据从旧片段传递到新片段时如何获取数据?

How to get data when data were passing from old fragment to new fragment?

旧片段。

lst.ItemClick += delegate(object sender, AdapterView.ItemClickEventArgs e) {
    //var intent = new Intent (this, typeof(TracksByGenres));
    //intent.PutStringArrayListExtra ("keys",   items);
    //StartActivity (intent);
    FragmentTransaction fragmentTx=this.FragmentManager.BeginTransaction();
    TracksByGenres fragTrack=new TracksByGenres();
    //get our item from listview
    fragmentTx.Replace(Resource.Id.fragmentContainer,fragTrack,items[e.Position]);      fragmentTx.AddToBackStack(null);
    fragmentTx.Commit();
};

新片段 (fragTrack)

public async override void OnActivityCreated(Bundle savedInstancesState)
{
    //What can I write? I want to get value from items[e.position] from old fragment
}

获取值的函数是什么?我搜索了 google,但没有我希望的结果。

修改您的片段以添加将接受如下数据的方法

这是您从中获取数据的第一个片段。

   public class FirstFragment :Fragment {
 public string mData;
 public void AddData(string data) {
 mData=data; } 
 public override View OnCreateView(LayoutInflater inflater, ViewGroup container, Bundle savedInstanceState) { 
// inflate layout and store in variable //you can use data here // myTextView.Text=mData; } }

这是您发送数据的第二个片段

    public class SecondFragment :Fragment {
 public string mData;
 public void AddData(string data) {
 mData=data; } 
 public override View OnCreateView(LayoutInflater inflater, ViewGroup container, Bundle savedInstanceState) { 
// inflate layout and store in variable //you can use data here // myTextView.Text=mData; } }

现在您可以在进行替换时传递数据,如下所示

SecondFragment aDifferentDetailsFrag = new SecondFragment(); 

aDifferentDetailsFrag.AddData(firstFragment.mData);
 //firstFragment is the instance of FirstFragment from where you are navigating to the secondfragment
// Replace the fragment that is in the View fragment_container (if applicable). 

fragmentTx.Replace(Resource.Id.fragment_container, aDifferentDetailsFrag);