1

I have three fragments in a viewpager set up like a sliding tab layout. I need to pass a string value from one fragment to another.

First, I tried setting up an interface like the answers here suggest How to pass data between fragments which did not work for me. The idea is that Fragment A tells the Main Activity and then the Main Activity tells Fragment B.

So I looked for different answers

http://android-er.blogspot.com/2012/06/communication-between-fragments-in.html

Looked promising but didn't work because I couldn't use the same functions with my code since I set up my viewpager with google's slidingtablayout instead of the old actionbar.

Now I've stumbled upon EventBus. And I really think this is my answer. I added it to my code just as both below answers suggest. Nothing crashes, but nothing works either.

I find this in the logcat:

D/Event: No subscribers registered for event class tk.abestudying.atob.TextChangedEvent D/Event: No subscribers registered for event class de.greenrobot.event.NoSubscriberEvent

Communication between Fragments in ViewPager

Communication between SlidingTabLayout tabs

Here is my code: Link removed

Please help. I have been trying out solutions for hours, but I am stumped. Thank you.

Edit: I got it working by being cautious and rewriting code.

Community
  • 1
  • 1
Abe
  • 153
  • 1
  • 8
  • Using `EventBus` seems like an overkill for this. If you haven't given up on `Interface`s yet, here a very simple and very elaborate explanation and example on **Inter-Fragment Communication** on YouTube https://www.youtube.com/watch?v=GDHnIZEJ76I. I hope this helps. – Elvis Chweya Feb 20 '16 at 22:36
  • Thanks for the suggestion Elvis, but I managed to get EventBus working perfectly – Abe Feb 21 '16 at 00:55

1 Answers1

2

Looks like you're missing the @Subscribe annotation. According to the README, a subscribing method should look like this:

@Subscribe public void onEvent(AnyEventType event) {/* Do something */};

Michiyo
  • 1,161
  • 1
  • 14
  • 33
  • @Subscribe was not needed. I just rewrote my code while being extremely cautious and I got it working. There was a sneaky problem with one of my layout files. Thank you.. – Abe Feb 21 '16 at 00:56
  • @Abe Any idea what the sneaky problem was? I might be experiencing that now. – Brett Aug 23 '16 at 10:35