1

I have Main Activity in that activity there is ReportFragment. In that ReportFragment there is Viewpager which contains 3 other fragments. I hav api call data in that 3 fragment. I want to send data from 3 nested fragment to the Parent fragment i.e. ReportFragment. which is child of Main Activity.

How to pass data in such scenario ?

Priya Sasane
  • 103
  • 1
  • 1
  • 6
  • You can use Otto library Its simple and easiest solution Tutotrial:http://www.recursiverobot.com/post/48752686831/playing-around-with-otto-on-android – Kamran Ahmed Khan Nov 02 '16 at 07:11
  • I used interface for this according to this tutorial : http://stackoverflow.com/questions/23142956/sending-data-from-nested-fragments-to-parent-fragment but getting someOtherNestFrag as null – Priya Sasane Nov 02 '16 at 10:44
  • Its a lot of code for little task, In my case i used Otto for communication b/w child and parent fragments and b/w service and Activity for updating UI – Kamran Ahmed Khan Nov 02 '16 at 12:33

2 Answers2

0

You can use EventBus for this case

Also you can use callbacs for it, but it will be callback hell

Sergey Zabelnikov
  • 1,855
  • 1
  • 14
  • 24
-1

If your fragment extend from fragment in support library. You can use getParentFragment() to get instance of ReportFragment. In ReportFragment, you have to implement some method to set data from child fragment.

Luc Le
  • 196
  • 9