Filterable ListView in Android

June 14, 2012

In this article, we are going to create a filterable listview application in Android. Filterable listview means that, whenever user types in some text, correspondingly the items in the listview will be filtered.

1. Create an Android project namely “ListViewFilterable”

Create new Android Project

Figure 1: Create new Android Project

2. Select a build target for this application

Android API Level

Figure 2: Select Android API Level

3. Enter the application details

Application Details

Figure 3: Enter application details

4. Open and update the file /res/layout/main.xml with the given below code :

<?xml version="1.0" encoding="utf-8"?>
<LinearLayout xmlns:android=""
    android:orientation="vertical" >



5. Open and update the file /src/in/wptrafficanalyzer/listviewfilterable with the given below code :

package in.wptrafficanalyzer.listviewfilterable;

import android.os.Bundle;
import android.widget.ArrayAdapter;
import android.widget.ListView;

public class MainActivity extends Activity {
    String[] countries = new String[] {
        "Sri Lanka",
        "North Korea",
        "South Korea",

    /** Called when the activity is first created. */
    public void onCreate(Bundle savedInstanceState) {

        // Creating an array adapter to host the list view items
        ArrayAdapter<String> adapter = new ArrayAdapter<String>(this, android.R.layout.simple_list_item_1, countries);

        // Get the reference of listview from the main layout
        ListView listView = (ListView) findViewById(;

        // This statement enables text filtering in the listview



6. Running the application

Filterable ListView in execution

Figure 4: Filterable ListView in execution

7. Download the source code

8. Testing this application

Testing of this application is discussed in the article “Testing Filterable ListView in Android

8. Reference

How to hire me?

I am George Mathew, working as software architect and Android app developer at

You can hire me on hourly basis or on project basis for Android applications development.

For hiring me, please mail your requirements to

My other blogs

Android Knowledge Quiz

Ready to test your knowledge in Android? Take this quiz :


2 Responses to Filterable ListView in Android

  1. Ammar on January 6, 2013 at 3:17 am

    How are you able to type on the screen? Don’t you need an EditText?

  2. Naren Lee on April 23, 2014 at 12:41 pm

    How to do filtering the listview populate with mysal database data having baseAdapter. If you can please help me.

Leave a Reply

Your email address will not be published. Required fields are marked *

Be friend at g+

Subscribe for Lastest Updates

FBFPowered by ®Google Feedburner