So basically I'm developing an app with a navigation bar and tabbed layout with a search icon added in the app bar. each of the tabs has a listview. Please give me an Idea on how to use the search to query in a fragment like this.
Asked
Active
Viewed 1,654 times
0

Ankita Shah
- 1,866
- 16
- 31

Claude Dubouzet
- 41
- 4
-
Please provide what you already have tried. – megaturbo Dec 20 '16 at 13:00
-
I deleted the code because it stops my app from running. Maybe I'll just try to make the searchview visible when the search icon is clicked. and follow the codes on some sample app with searchview. – Claude Dubouzet Dec 20 '16 at 13:04
-
Use this link http://stackoverflow.com/questions/21585326/implementing-searchview-in-action-bar – Ranjan Dec 20 '16 at 13:05
-
It's hard to tell without anything to rely on. Have you already checked this Android guide: https://developer.android.com/guide/topics/search/search-dialog.html ? – megaturbo Dec 20 '16 at 13:06
-
suggestions are noted. thank you. – Claude Dubouzet Dec 20 '16 at 13:12
1 Answers
1
Try this
@Override
public void onPrepareOptionsMenu(Menu menu)
{
// Associate searchable configuration with the SearchView
SearchManager searchManager = (SearchManager)getActivity(). getSystemService(Context.SEARCH_SERVICE);
SearchView searchView = (SearchView) menu.findItem(R.id.search).getActionView();
searchView.setSearchableInfo(searchManager.getSearchableInfo(getActivity().getComponentName()));
searchView.setOnQueryTextListener(new SearchView.OnQueryTextListener()
{
@Override
public boolean onQueryTextSubmit(String query)
{
return false;
}
@Override
public boolean onQueryTextChange(String query)
{
// pass query to your filter
return true;
}
});
}

Gowthaman M
- 8,057
- 8
- 35
- 54

gautam
- 522
- 3
- 14