How To Pass Data From One Fragment To Another Fragment?

Forums AndroidHow To Pass Data From One Fragment To Another Fragment?
Staff asked 2 years ago

Answers (1)

Add Answer
Ajay Marked As Accepted
Staff answered 2 years ago

You can do something like below,

String cid=id.getText().toString();
 Fragment fr=new friendfragment();
 FragmentManager fm=getFragmentManager();
 android.app.FragmentTransaction ft=fm.beginTransaction();
 Bundle args = new Bundle();
 args.putString("CID", cid);
 fr.setArguments(args);
 ft.replace(R.id.content_frame, fr);
 ft.commit();

To receive the data do the following,

@Override
public View onCreateView(LayoutInflater inflater, ViewGroup container,
        Bundle savedInstanceState) {
    String strtext = getArguments().getString("CID");    
    return inflater.inflate(R.layout.fragment, container, false);
}

 

Subscribe

Select Categories