Easy way to pass data(e.g.string) from fragment one to last fragment, I mean ,how to (save, set or put ) data, and (show, get ) in the last fragment, I used arguments to pass from fragment 1 to fragment two, but I don´t have any idea how to pass to last fragment .
Asked
Active
Viewed 53 times
3 Answers
1
you can pass values by Bundle.
for example:
Fragment fragment = new YourFragment();
Bundle args = new Bundle();
args.putString(ARG_PARAM1, param1);
args.putString(ARG_PARAM2, param2);
fragment.setArguments(args);
FragmentManager manager = activity.getSupportFragmentManager();
FragmentTransaction ft = manager.beginTransaction();
ft.addToBackStack(null);
ft.add(R.id.container_layout, fragment);
ft.commit();
if you dont want to add or replace fragment. (incase if your fragment is already open) then you can make Interface in that fragment and implement Interface on your BaseActivity.

Learn Pain Less
- 2,274
- 1
- 17
- 24
-
ok let my try, and thanks :) – Luis Gilberto Ramirez Leal Sep 11 '16 at 04:31
1
pass value
Fragment fragment = new YourFragment();
FragmentManager manager = activity.getSupportFragmentManager();
FragmentTransaction ft = manager.beginTransaction();
Bundle args = new Bundle();
args.putString(ARG_PARAM1, param1);
args.putString(ARG_PARAM2, param2);
fragment.setArguments(args);
ft.addToBackStack(null);
ft.replace(R.id.container_layout, fragment).commit();
get value
@Override
public View onCreateView(LayoutInflater inflater, ViewGroup container,
Bundle savedInstanceState) {
yourvalue1 = getArguments().getString("ARG_PARAM1");
yourvalue2 = getArguments().getString("ARG_PARAM2");
final View view = inflater.inflate(R.layout.yourlayout, container, false);
retrun view;
}

Ramesh Prajapati
- 654
- 6
- 10
0
You can pass data from any fragment to any fragment with Bundles as per suggested by another answer, as per documentation here suggested communication pattern.
Or you can make singleton and can access variables from it,see my answer here it is already several time asked question,so please search first before directly asking question.
-
thanks dude and apologies for ask, it´s my first day :) – Luis Gilberto Ramirez Leal Sep 11 '16 at 04:30
-
U r welcome to SO community please spent 5 minutes on this to get guidelines for how to ask question. here : http://stackoverflow.com/help/how-to-ask – TapanHP Sep 11 '16 at 06:25