0

i have 2 fragments

in 1st fragment i am calling a 2nd fragment on button click which returns data(on click on list items) and again open 1st fragment with the result displayed (i.e some String data of list item).

But the problem is when i comeback from 2nd to 1st again after selection in 2nd fragment my 1st fragment is displayed only but do not react on button click.

this is my first fragment

i have searched lot but i found activity fragment communication only not fragment to fragment

if any body has solution for fragment to fragment only.please help

3 Answers3

1

There are a lot of ways, here some hints.

Generally speaking you can use "listeners" (interfaces)

More elegant way using "event bus" paradigm, a clean and simple library is Otto

Community
  • 1
  • 1
Luca Sepe
  • 2,435
  • 1
  • 20
  • 26
0

Another (slightly dirty) way if you are using the compatibility library would be to use the LocalBroadcastManager. Your fragments can send (and listen for) local broadcasts to notify each other of events...

C B J
  • 1,838
  • 16
  • 22
0

Try like this (Example an integer array):

    //Create a public class:
    public class Values{

    public static int[] val = null;

    }


    //Set array in one fragment:
    Values.val = int[] arr1;//arr1 containing your values


    //Get array in another fragment:
    int[] arr2 = Values.val;
fida1989
  • 3,234
  • 1
  • 27
  • 30