Passing data from one fragment to another

后端 未结 4 1888
星月不相逢
星月不相逢 2020-12-06 20:25

I have an Activity with two fragments and I need to pass a string from FragmentA to FragmentB.

To pass the data, I have this in my FragmentA:

    Int         


        
4条回答
  •  佛祖请我去吃肉
    2020-12-06 20:57

    to pass data between Fragments you can use setArguments(Bundle b). For instance:

    public class FragmentA extends Fragment {
    
      public static FragmentA newInstance(String name) {
        Bundle bundle = new Bundle();
        bundle.putString("name", name);
        FragmentA f = new FragmentA(); 
        f.setArguments(bundle);
        return f;
      }
    
    }
    

提交回复
热议问题