i have 3 ArrayList> that I want to pass to 3 fragments. Besides making them static, what is the best approach to do this?
Share
Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.
Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.
Lost your password? Please enter your email address. You will receive a link and will create a new password via email.
Please briefly explain why you feel this question should be reported.
Please briefly explain why you feel this answer should be reported.
Please briefly explain why you feel this user should be reported.
You can create listener callback interfaces and implement them in your fragments. Something like this:
In your activity create this interface:
then obtain your fragment by using findFragmentById or findFragmentByTag and assign it to a listener:
You can then call methods of that interface and your fragment will receive callbacks.
The second and more easier way of communication between fragments and activities is BroadcastReceivers. You can register some BroadcastReceiver in your fragments and then call sendBroadcast() from activity. Your list of data can be put in a bundle of that broadcast message.