[英]How can I send information from my searchview in my main actiity to one of the fragments from my viewpager
My main activity has a viewpager with 3 fragments. 我的主要活动是一个包含3个片段的viewpager。 In fragment1 I have a recyclerview that shows some information. 在fragment1中,我有一个显示一些信息的recyclerview。 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. 回到我的主要活动中,我有一个搜索视图,我的问题是如何将信息从我的主要活动传递给fragment1,以便可以根据用户在搜索视图中输入的内容更新回收站视图。
I already have the searchview and the listener with onQueryTextSubmit and onQueryTextChange methods to get the string from the searchview 我已经有了searchview和带有onQueryTextSubmit和onQueryTextChange方法的侦听器,以从searchview获取字符串
Thank you. 谢谢。
You can use the FragmentPagerAdapter
as a bridge. 您可以将FragmentPagerAdapter
用作桥。 Add a method to your FragmentPagerAdapter
: 向您的FragmentPagerAdapter
添加一个方法:
public void onQueryTextChange(String text) {
fragment1.onQueryTextChange(String text);
}
In fragment1 you should also add a method: 在fragment1中,您还应该添加一个方法:
public void onQueryTextChange(String text) {
//do something
}
Then in your Activity
, when search text changed, call: 然后在“ Activity
,当搜索文本更改时,调用:
theAdapter.onQueryTextChange(text);
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.