Sunday, April 21, 2013

[android help] Android Fragment pass information between fragements of same activity


I am not sure about other good options but you can definitely do the following.


say you have an activity named A and it has contained to fragment b and c. you need to send data from b to c.


as both b and c are child of activity A then can access the method of A. And A can also access the child fragments b and c. So to pass info from b to c create a method in A which will pass info to c and call it from b.


To be more specific you can see the doc.


So the fragment can access the Activity instance with getActivity() and easily call method



getActivity().passInfoToC(data);


Likewise, your activity can call methods in the fragment by acquiring a reference to the Fragment from FragmentManager, using findFragmentById() or findFragmentByTag(). For example:



ExampleFragment fragment = (ExampleFragment)getFragmentManager().findFragmentById(R.id.example_fragment);
fragment.setData(data);


Then access a method to pass data.



.

stackoverflow.comm

No comments:

Post a Comment

Google Voice on T-Mobile? [General]

Google Voice on T-Mobile? So I recently switched from a GNex on Verizon to a Moto X DE on T-Mobile. I had always used Google Voice for my v...