Created
February 14, 2016 14:26
-
-
Save wangchauyan/810879253201233ed7b1 to your computer and use it in GitHub Desktop.
Create a search view in your fragment
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
public void onCreateView (LayoutInflater inflater, ViewGroup container, | |
Bundle savedInstanceState) { | |
// enable options menus | |
setHasOptionsMenu(true); | |
} | |
public void onCreateOptionsMenu(Menu menu, MenuInflater inflater) { | |
super.onCreateOptionsMenu(menu, inflater); | |
// add menu item | |
MenuItem item = menu.add("searchOpt"); | |
item.setShowAsAction(MenuItem.SHOW_AS_ACTION_IF_ROOM); | |
SearchView searchView = new SearchView(getActivity()); | |
// setup search view listener | |
searchView.setOnQueryTextListener(new SearchView.OnQueryTextListener() { | |
@Override | |
public boolean onQueryTextSubmit(String s) { | |
doSearch(s); | |
} | |
@Override | |
public boolean onQueryTextChange(String newText) { | |
return true; | |
} | |
}); | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment