Hello everyone

In today’s tutorial I will show you how to filter a ListView based on an input from the EditText.
This is really simple we just need to call getFilter().filter(search_string) on the adapter to filter the values from the ListViews.
Just take a look at this example.

Here is the layout file main.xml

<?xml version="1.0" encoding="utf-8"?>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
    android:orientation="vertical" android:layout_width="fill_parent"
    <EditText android:layout_width="fill_parent"
        android:layout_height="wrap_content" android:id="@+id/filterText">
    <ListView android:layout_height="wrap_content" android:id="@+id/android:list"

Here is the java file named FilterListViewsDemo.java

package pack.coderzheaven;

import java.util.ArrayList;
import java.util.List;
import android.app.ListActivity;
import android.os.Bundle;
import android.text.Editable;
import android.text.TextWatcher;
import android.widget.ArrayAdapter;
import android.widget.EditText;

public class FilterListViewsDemo extends ListActivity {
    public void onCreate(Bundle savedInstanceState) {
        final ArrayAdapter<String> adapter = new ArrayAdapter<String>(this,
                android.R.layout.simple_list_item_1, android.R.id.text1,
        EditText filterEditText = (EditText) findViewById(R.id.filterText);
        filterEditText.addTextChangedListener(new TextWatcher() {

            public void onTextChanged(CharSequence s, int start, int before,
                    int count) {

            public void beforeTextChanged(CharSequence s, int start, int count,
                    int after) {

            public void afterTextChanged(Editable s) {

    private List<String> getModel() {
        List<String> list = new ArrayList<String>();
        return list;

You can download the full source code from here



  1. seo optimalizace December 16, 2011 at 5:03 pm

    I suspect my implementation of the idea I have using Listview may not be suitable, from what you have suggested. perhaps you can enlighten me on a better method? I would like my application to achieve the same functionality as that of the edit contacts’ “add phone number”. It is able to add and remove rows from the view dynamically

    • James December 16, 2011 at 6:44 pm

      You can give an id to a view in each row and when you click on that row, pick that id and delete the corresponding row from your array and then reload the list.

  2. Susan January 16, 2012 at 7:33 am

    > List list = new ArrayList();

    Why is the 1st word “List” and not “ArrayList”?

    • James January 16, 2012 at 7:57 pm

      U can use this also

      ArrayList list = new ArrayList();

  3. Pingback: Android dialog with ListView | Coderz Heaven

  4. Dolly April 1, 2017 at 3:59 am

    I’m relaly into it, thanks for this great stuff!


Leave a Reply to James Cancel

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




Theme by HermesThemes

Copyright © 2018 CoderzHeaven. All Rights Reserved

Please wait...

Subscribe to our newsletter

Want to be notified when our article is published? Enter your email address and name below to be the first to know.