Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • Home
  • SEARCH
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 4096130
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 20, 20262026-05-20T20:00:16+00:00 2026-05-20T20:00:16+00:00

I have a ListView with a custom item layout backed by a SimpleCursorAdapter. I’d

  • 0

I have a ListView with a custom item layout backed by a SimpleCursorAdapter. I’d like the user to be able to type text into an EditText box and have the ListView automatically filter as they type. It looks like this is very simple to do with an ArrayAdapter, as described here.

Unfortunately, I’m not having any luck getting it working with a SimpleCursorAdapter. I’ve tried adding extra methods as described here, but that example is for an AutoCompleteTextView instead of a ListView. I haven’t been able to get anything working for my ListView.

Can somebody provide me with an example of filtering a SimpleCursorAdapter-backed ListView with an EditText box?

public class DirectoryListActivity extends DirectoryActivity {

    private static SimpleCursorAdapter adapter;

    @Override
    public void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);

        setContentView(R.layout.directory_list);

        fillPeopleListView();

        EditText etext=(EditText)findViewById(R.id.search_box);
        etext.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) {
                adapter.getFilter().filter(s.toString());

            }
        });

    }

    private void fillPeopleListView() {
        // Populate the ListView
        SQLiteQueryBuilder queryBuilder = new SQLiteQueryBuilder();
        queryBuilder.setTables(
            directoryPeople.PEOPLE_TABLE
        );

        String asColumnsToReturn[] = { 
                directoryPeople.PEOPLE_TABLE + "."
                + directoryPeople.LAST_NAME + "," +
                directoryPeople.PEOPLE_TABLE + "."
                + directoryPeople.FIRST_NAME + "," +
                directoryPeople.PEOPLE_TABLE + "."
                + directoryPeople.MIDDLE_NAME + "," +
                directoryPeople.PEOPLE_TABLE + "."
                + directoryPeople.JOB_TITLE + "," +
                directoryPeople.PEOPLE_TABLE + "."
                + directoryPeople._ID
        };

        mCursor = queryBuilder.query(mDB, asColumnsToReturn, null, null,
                null, null, directoryPeople.DEFAULT_SORT_ORDER);

        startManagingCursor(mCursor);

        adapter = new SimpleCursorAdapter(this,
                R.layout.directory_people_item, mCursor,
                new String[]{
                    directoryPeople.LAST_NAME,
                    directoryPeople.FIRST_NAME,
                    directoryPeople.MIDDLE_NAME,
                    directoryPeople.JOB_TITLE},
                new int[]{
                    R.id.txtLastName,
                    R.id.txtFirstName,
                    R.id.txtMiddle,
                    R.id.txtTitle} 
        ); 

        ListView av = (ListView)findViewById(R.id.listPeople);
        av.setAdapter(adapter);
        av.setFastScrollEnabled(true);

        adapter.setFilterQueryProvider(new FilterQueryProvider() {

            public Cursor runQuery(CharSequence constraint) {
                String partialValue = constraint.toString();

                SQLiteQueryBuilder queryBuilder = new SQLiteQueryBuilder();

                String asColumnsToReturn[] = { 
                        directoryPeople.PEOPLE_TABLE + "."
                        + directoryPeople.LAST_NAME + "," +
                        directoryPeople.PEOPLE_TABLE + "."
                        + directoryPeople.FIRST_NAME + "," +
                        directoryPeople.PEOPLE_TABLE + "."
                        + directoryPeople.MIDDLE_NAME + "," +
                        directoryPeople.PEOPLE_TABLE + "."
                        + directoryPeople.JOB_TITLE + "," +
                        directoryPeople.PEOPLE_TABLE + "."
                        + directoryPeople._ID
                };

                Cursor c = queryBuilder.query(mDB, asColumnsToReturn, directoryPeople.LAST_NAME + " LIKE " + partialValue, null,
                        null, null, directoryPeople.DEFAULT_SORT_ORDER);


                return c;
            }
        });

}

Here’s my layout code, as requested. Main layout:

<?xml version="1.0" encoding="utf-8"?>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
    android:layout_width="match_parent"
    android:layout_height="match_parent"
    android:orientation="vertical"
    android:background="@android:color/white">
    <include android:id="@+id/lytHeadBar" layout="@layout/headbar" />
    <include android:id="@+id/lytTitleBar" layout="@layout/titlebar" />
    <EditText android:layout_width="fill_parent"
        android:layout_height="wrap_content"
        android:hint="Type a name..."
        android:maxLines="1" android:inputType="textFilter|textCapWords" android:id="@+id/search_box"/>
    <ListView
        android:layout_width="match_parent"
        android:layout_height="wrap_content"
        android:id="@+id/listPeople"
        android:divider="@android:drawable/divider_horizontal_dark"
        android:cacheColorHint="@android:color/white" />
</LinearLayout>

List item layout:

<?xml version="1.0" encoding="utf-8"?>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
    android:id="@+id/lytItem"
    android:layout_height="wrap_content"
    android:layout_width="match_parent"
    android:orientation="vertical"
    android:paddingLeft="10dp"
    android:paddingRight="10dp"
    android:background="@drawable/item_line_bottom">
    <LinearLayout android:id="@+id/nameLine"
        android:layout_height="wrap_content"
        android:layout_width="match_parent"
        android:orientation="horizontal">
            <TextView
                android:id="@+id/txtLastName"
                android:layout_width="wrap_content"
                android:layout_height="wrap_content"
                android:textSize="20sp"
                android:textStyle="bold"
                android:textColor="@android:color/black"
                android:text="lastname" />
            <TextView
                android:id="@+id/nameSpace1"
                android:layout_width="wrap_content"
                android:layout_height="wrap_content"
                android:textStyle="bold"
                android:textSize="20sp"
                android:textColor="@android:color/black"
                android:text=", " />
            <TextView
                android:id="@+id/txtFirstName"
                android:layout_width="wrap_content"
                android:layout_height="wrap_content"
                android:textStyle="bold"
                android:textSize="20sp"
                android:textColor="@android:color/black"
                android:text="firstname" />
            <TextView
                android:id="@+id/nameSpace2"
                android:layout_width="wrap_content"
                android:layout_height="wrap_content"
                android:textStyle="bold"
                android:textSize="20sp"
                android:textColor="@android:color/black"
                android:text=" " />
            <TextView
                android:id="@+id/txtMiddle"
                android:layout_width="wrap_content"
                android:layout_height="wrap_content"
                android:textStyle="bold"
                android:textSize="20sp"
                android:textColor="@android:color/black"
                android:text="middle" />    
        </LinearLayout>
    <LinearLayout android:id="@+id/titleLine"
        android:layout_height="wrap_content"
        android:layout_width="match_parent"
        android:orientation="horizontal">
        <TextView
            android:id="@+id/txtTitle"
            android:layout_width="match_parent"
            android:layout_height="wrap_content"
            android:textSize="16sp"
            android:textColor="@android:color/black"
            android:text="title" android:ellipsize="marquee"/>
    </LinearLayout>
</LinearLayout>
  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-05-20T20:00:18+00:00Added an answer on May 20, 2026 at 8:00 pm

    Finally managed to solve the issue! Answer can be found here: ListView, SimpleCursorAdapter, an an EditText filter — why won't it do anything?

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I have a ListView backed by a custom adapter based on a CursorAdapter. The
I have a ListView inside another ListView, and I'd like to hide a table
I have a listview with custom rows and that extends SimpleAdapter. Each row consist
I have a ListView powered by a custom adapter that dynamically changes the background
I am attempting to create a custom Adapter for my ListView since each item
I have a Custom ListView with an imageview and 2 TextViews above each other
I have got ListView with a custom Adapter. Every row contains clickable buttons and
I have a custom listview row that contains a number of textView components. Instead
i got the following problem. i have a ListView with custom rows consisting of
i have a ListView with a custom Servizio object in every row. I'm using

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.