Android Simple ListView - Search/Filter

| Page Views: 9193 android search filter

Android Simple ListView Search/Filter Tutorial and Example.

How to search or filter a simple ListView in android.

Google search engine is the most visited website in the whole world. This tells us something about us humans and our need to always search and filter through information.

The worldwide web is really vast, and we cannot be able to use it conveniently by just remembering website urls or going through portals to find the content we want.

Instead we simply search. Now today we are not developing another search engine. Instead we look at a simple example in android, how to search through a list using searchview. Call it search or filter, but we find the information we want by typing it in the searchview. SearchView is a widget that was added to android in API 11.

It provides s imple edittext where user can enter a query and submit it to the search provider. For us we simply search through a simple listview using searchview.

Project Demo


Common Questions this example explores

  • Android SearchView example.
  • How to search a simple listview in android.
  • Android SearchView arrayadapter example.
  • How to search/filter in android.

This example was written with the following tools:

  • Windows 8.1
  • Eclipse IDE
  • Java Language
  • Bluestacks Emulator

Lets have a look at the source code.

Our MainActivity Class

Purpose :

  1. Reference our ListView and SearchView from xml
  2. Bind our data to ListView using ArrayAdapter.
  3. Handle our SearchView's onQueryTextChangeListener.
  4. Filter or Search dynamically
package com.tutorials.simplelistviewfilter;

import android.os.Bundle;
import android.view.Menu;
import android.widget.ArrayAdapter;
import android.widget.ListView;
import android.widget.SearchView;
import android.widget.SearchView.OnQueryTextListener;

public class MainActivity extends Activity {

  ListView lv;
  SearchView sv;

    String[] teams={"Man Utd","Man City","Chelsea","Arsenal","Liverpool","Totenham"};
  ArrayAdapter<String> adapter;

    protected void onCreate(Bundle savedInstanceState) {

        lv=(ListView) findViewById(;
        sv=(SearchView) findViewById(;

        adapter=new ArrayAdapter<String>(this, android.R.layout.simple_list_item_1,teams);

        sv.setOnQueryTextListener(new OnQueryTextListener() {

      public boolean onQueryTextSubmit(String text) {
        // TODO Auto-generated method stub
        return false;

      public boolean onQueryTextChange(String text) {


        return false;

    public boolean onCreateOptionsMenu(Menu menu) {
        // Inflate the menu; this adds items to the action bar if it is present.
        getMenuInflater().inflate(, menu);
        return true;



Our ActivityMain layout


  1. Basically display whatever widgets we want to use,in this case ListView and SearchView.
<RelativeLayout xmlns:android=""
    tools:context=".MainActivity" >



        android:layout_marginTop="22dp" >



YouTube Video

How To Run

  1. This project was created by Eclipse.
  2. Therefore just copy the code and use in your project in android studio, it's still android anyway and expandableListview is the same regardless of the IDE. So copy paste the code to your android studio project.

How do You Feel after reading this?

According to scientists, we humans have 8 primary innate emotions: joy, acceptance, fear, surprise, sadness, disgust, anger, and anticipation. Feel free to tell us how you feel about this article using these emotes or via the comment section.

About Me.

After completing his Software Engineering bachelors program, Oclemy(Clement Ochieng) these days is a man of two lives. At day he works for a startup in Nairobi, Kenya. At night he works tirelessly on building ProgrammingWizards TV, a tv channel for student coders and this website to help share the source code. In between he practices Meditation and Self actualization to help him keep balance. He also likes going for long solo walks to connect more with nature.


What do You Think

Previous Post Next Post