In the documentation you have the article:
Communicating with Other Fragments
One solution would be to send the data by means of a interfaz
:
public class HeadlinesFragment extends ListFragment {
OnHeadlineSelectedListener mCallback;
// Container Activity must implement this interface
public interface OnHeadlineSelectedListener {
public void onArticleSelected(int position);
}
@Override
public void onAttach(Activity activity) {
super.onAttach(activity);
// This makes sure that the container activity has implemented
// the callback interface. If not, it throws an exception
try {
mCallback = (OnHeadlineSelectedListener) activity;
} catch (ClassCastException e) {
throw new ClassCastException(activity.toString()
+ " must implement OnHeadlineSelectedListener");
}
}
...
}
and another way to send data between Fragments
is to send your bundle, or data when instances other Fragment
:
public class myFragment {
public static myFragment newInstance(@NonNull final ArrayList<String> fooList) {
myFragment f = new myFragment();
Bundle args = new Bundle(); //* Bundle a recibir con datos.
args.putParcelableArrayList(“my_key”, fooList);
f.setArguments(args);
return f;
}
public ArrayList<String> getFoo() {
final Bundle bundle = getArguments();
bundle != null ? bundle.getParcelableArrayList("mi_llave") : null;
}
}