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

  1. public boolean onQueryTextSubmit(String query): It searches the query on the submission of content over SearchView editor. It is case dependent.
  2. 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

android Searchview  1
android Searchview  2 android Searchview  3




Latest Courses