How to pass Arguments to Fragment from Activity

后端 未结 4 1163
既然无缘
既然无缘 2021-01-05 18:37

I have an activity which instantiates and populates a Fragment through a adopter class. I want to pass values/objects to this Fragment adopter class so that i can dictate la

4条回答
  •  囚心锁ツ
    2021-01-05 18:55

    You can use Bundle to transfer data from activity to fragments or transfre data from fragment to fragment.

    Bundle bundle = new Bundle();
    DisplayDataList fragment = new DisplayDataList();
    bundle.putString("listitem", "Buyer,Seller");
                fragment.setArguments(bundle);
    
                getFragmentManager().beginTransaction().replace(
                        R.id.frame_container, fragment).addToBackStack(null).commit();
    

    Where you want to recieve that bundle i.w in DisplayDataList Fragment class. You have to use getArguments() method.

    DisplayDataList

     Bundle bundle = getArguments();
                String getdata = bundle.getString("listitem");
                System.out.println("Data got-->>> " + getdata);
    

    Hope this will help you.

提交回复
热议问题