-2

I am trying to pass data between nested fragments in the following way:

From stored data in one class, I have loaded data into viewPager fragment (Fragment #1), displayed as such: Fragment#1

Now when the Btn is clicked, another fragment (Fragment#2), should launch with data that corresponds with Fragment#1, displayed as such: Fragment#2 The data for Fragment#2 is coming from Fragment#1, which is receiving the data from the class which has the stored data. Suppose there are multiple, Fragment#1 components in the same viewPager that have the Btn and when clicked would have to show Fragment#2 with data that are specific to each of the Fragment#1 components. What would be the best approach at trying to tackle this?

I have tried a similar approach, where instead of nested fragments, a fullscreendialog similar to Fragment#2 would appear. But that approach was futile since the dialogs could not properly keep track of the fragment position.

Tahfimul
  • 9
  • 4
  • I get the point.. but your illustration is poor. All you're trying to do is to pass data from one fragment to another, we don't need all of these stories. They belabor the point. – Taslim Oseni Jul 08 '18 at 23:32
  • Possible duplicate of [How to pass data between fragments](https://stackoverflow.com/questions/5194548/how-to-pass-data-between-fragments) – Taslim Oseni Jul 08 '18 at 23:35

1 Answers1

0

Option 1:

Implement interfaces (this is the official way to communicate): https://developer.android.com/training/basics/fragments/communicating

Option 2:

EvenBus library (easier but be careful)

Liar
  • 1,235
  • 1
  • 9
  • 19