87
Android SearchView
Android SearchView provides user interface to search query submitted over search provider. SearchView widget can be implemented over ToolBar/ActionBar or inside a layout.
SearchView is by default collapsible and set to be iconified using setIconifiedByDefault(true) method of SearchView class. For making search field visible, SearchView uses setIconifiedByDefault(false) method.
Methods of SearchView
- public boolean onQueryTextSubmit(String query): It searches the query on the submission of content over SearchView editor. It is case dependent.
- public boolean onQueryTextChange(String newText): It searches the query at the time of text change over SearchView editor.
Example of SearchView
Let’s see the example of SearchView over layout, searching data in a ListView.
activity_main.xml
Create an activity_main.xml file in layout folder containing ScrollView and ListView.
File: activity_main.xml
Activity class
File: MainActivity.java
Output
Next TopicAndroid SearchView on Toolbar