0

My main activity has a viewpager with 3 fragments. In fragment1 I have a recyclerview that shows some information. Back into my main activity I have a searchview, my question is how can I pass the information from my mainactivity to the fragment1 so I can update my recyclerview based on what the user put in the searchview.

I already have the searchview and the listener with onQueryTextSubmit and onQueryTextChange methods to get the string from the searchview

Thank you.

  • Possible duplicate of [Send data from activity to fragment in android](http://stackoverflow.com/questions/12739909/send-data-from-activity-to-fragment-in-android) – Manoj Perumarath Nov 10 '16 at 03:38

1 Answers1

0

You can use the FragmentPagerAdapter as a bridge. Add a method to your FragmentPagerAdapter:

public void onQueryTextChange(String text) {
    fragment1.onQueryTextChange(String text);
}

In fragment1 you should also add a method:

public void onQueryTextChange(String text) {
    //do something
}

Then in your Activity, when search text changed, call:

theAdapter.onQueryTextChange(text);
shhp
  • 3,653
  • 2
  • 18
  • 23