Reputation: 6813
I added some code to oncreate options menu like this
SearchManager searchManager =
(SearchManager) getSystemService(Context.SEARCH_SERVICE);
SearchView searchView =
(SearchView) menu.findItem(R.id.search).getActionView();
searchView.setSearchableInfo(
searchManager.getSearchableInfo(getComponentName()));
Also I created a xml file in xml directory and I did what is said in this.But I don't know how to pass search query and get the result. Executing this getting action bar disappeared.
Upvotes: 0
Views: 2609
Reputation: 11244
Android Search View Example in android Working Source Code
https://drive.google.com/open?id=0BzBKpZ4nzNzUajJhNEV2N25qWlU
Upvotes: 0
Reputation: 1731
Furthermore if you want have some callback use the code below, on putting some query and fetch it.
searchView.setOnQueryTextListener(new SearchView.OnQueryTextListener() {
@Override
public boolean onQueryTextSubmit(String query) {
return false;
}
@Override
public boolean onQueryTextChange(String s) {
return false;
}
});
Upvotes: 6