Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to use setArguments() and getArguments() methods in Fragments?

I have 2 fragments: (1)Frag1 (2)Frag2.

Frag1

bundl = new Bundle(); bundl.putStringArrayList("elist", eList);  Frag2 dv = new Frag2(); dv.setArguments(bundl); FragmentTransaction ft = getFragmentManager().beginTransaction(); ft.replace(R.id.the_fragg,dv); ft.show(getFragmentManager().findFragmentById(R.id.the_fragg));  ft.addToBackStack(null); ft.commit(); 

How do I get this data in Frag2?

like image 754
Android_programmer_camera Avatar asked Mar 24 '11 21:03

Android_programmer_camera


1 Answers

Just call getArguments() in your Frag2's onCreateView() method:

public class Frag2 extends Fragment {       public View onCreateView(LayoutInflater inflater,          ViewGroup containerObject,          Bundle savedInstanceState){          //here is your arguments          Bundle bundle=getArguments();           //here is your list array          String[] myStrings=bundle.getStringArray("elist");         } } 
like image 178
ashakirov Avatar answered Sep 19 '22 19:09

ashakirov