1

I have activity with CoordinatorLayout, AppBarLayout, Toolbar, TabLayout, ViewPAger and 2 fragments.

Fragment description:

  1. with settings (ListView filled with data)
  2. game which is operating based on chosen data

Idea is to go back and forth between 1st and 2nd tab (fragment). On each swipe from 1nd to 2st, 2nd tab shold be a bit updated based on chosen data in 1st tab.

How can I send those chosen data from 1st tab to 2nd on swipe event.

sovadn
  • 15
  • 3
  • 1
    show your code please – Fabio Venturi Pastor Feb 19 '16 at 08:38
  • You could have a method in your TabActivity(that hosts your tabs) say refreshMe(int tabId). Call this method from your tabs and get your tab content refreshed – cafebabe1991 Feb 19 '16 at 08:43
  • Possible duplicate of [Android: Saving form data on a swipe rather than from a button](http://stackoverflow.com/questions/35476874/android-saving-form-data-on-a-swipe-rather-than-from-a-button) – yennsarah Feb 19 '16 at 08:54
  • @Amy OP doesn't want to save data, just want to send data between fragment in `viewpager` – Ravi Feb 19 '16 at 09:09
  • Title is misleading it's about getting the data from first fragment to show in second via swipe in `ViewPager`. Data storage, temporary or long lasting is depending on OP and case scenarios. I believe settings should last longer than an app lifecycle, so I marked this as duplicate. – yennsarah Feb 19 '16 at 09:11
  • Sorry for misleading title. I've changed it to "How to send data between fragments when swiping tabs in ViewPager" – sovadn Feb 19 '16 at 09:14

1 Answers1

-1

Use EventBus.

EventBus simplifies the communication between components. It performs well with Activities, Fragments, and background threads.

Here is nice example of EventBus.

EventBus will help you to send data between two components.

Ravi
  • 34,851
  • 21
  • 122
  • 183
  • your reputation says you are experienced member of SO. So, you should know, link only answers are no good. Please provide few description instead of just linking your blog post. – Krrishnaaaa Nov 28 '16 at 08:20