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

  • SEARCH
  • Home
  • 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 3627964
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 18, 20262026-05-18T23:57:20+00:00 2026-05-18T23:57:20+00:00

I have a list of countries in a database. I have created a select

  • 0

I have a list of countries in a database. I have created a select country activity that consists of a edit box for filtering and a list which displays the flag and country name.

When the activity starts the list shows the entire list of countries sorted alphabetically – works fine. When the customer starts typing into the search box I want the list to be filtered based on their typing. My database query was previously working in an AutoCompleteView (I just want to switch to a separate text box and list) so I know my full query and my constraint query are working. What I did was add a TextWatcher to the EditText view and every time the text is changed I invoke the list’s SimpleCursorAdapter runQueryOnBackgroundThread with the edit boxes text as the constraint. The trouble is the list is never updated. I have set breakpoints in the debugger and the TextWatcher does make the call to runQueryOnBackgroundThread and my FilterQueryProvider is called with the expected constraint. The database query goes fine and the cursor is returned.

The cursor adapter has a filter query provider set (and a view binder to display the flag):

    SimpleCursorAdapter adapter = new SimpleCursorAdapter (this,
            R.layout.country_list_row, countryCursor, from, to);
    adapter.setFilterQueryProvider (new CountryFilterProvider ());
    adapter.setViewBinder (new FlagViewBinder ());

The FitlerQueryProvider:

private final class CountryFilterProvider implements FilterQueryProvider {

    @Override
    public Cursor runQuery (CharSequence constraint) {
        Cursor countryCursor = myDbHelper.getCountryList (constraint);
        startManagingCursor (countryCursor);
        return countryCursor;
    }
}

And the EditText has a TextWatcher:

    myCountrySearchText = (EditText)findViewById (R.id.entry);
    myCountrySearchText.setHint (R.string.country_hint);
    myCountrySearchText.addTextChangedListener (new TextWatcher() {
        @Override
        public void afterTextChanged (Editable s) {
            SimpleCursorAdapter filterAdapter = (SimpleCursorAdapter)myCountryList.getAdapter ();
            filterAdapter.runQueryOnBackgroundThread (s.toString ());
        }


        @Override
        public void onTextChanged (CharSequence s, int start, int before, int count) {
            // no work to do
        }


        @Override
        public void beforeTextChanged (CharSequence s, int start, int count, int after) {
            // no work to do
        }
    });

The query for the database looks like this:

public Cursor getCountryList (CharSequence constraint)  {
    if (constraint == null  ||  constraint.length () == 0)  {
        //  Return the full list of countries
        return myDataBase.query (DATABASE_COUNTRY_TABLE, 
                new String[] { KEY_ROWID, KEY_COUNTRYNAME, KEY_COUNTRYCODE }, null, null, null, 
                null, KEY_COUNTRYNAME);
    }  else  {
        //  Return a list of countries who's name contains the passed in constraint
        return myDataBase.query (DATABASE_COUNTRY_TABLE, 
                new String[] { KEY_ROWID, KEY_COUNTRYNAME, KEY_COUNTRYCODE }, 
                "Country like '%" + constraint.toString () + "%'", null, null, null, 
                "CASE WHEN Country like '" + constraint.toString () + 
                "%' THEN 0 ELSE 1 END, Country");
    }
}

It just seems like there is a missing link somewhere. Any help would be appreciated.

Thanks,

Ian

  • 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-18T23:57:21+00:00Added an answer on May 18, 2026 at 11:57 pm

    It seems like you’re doing a lot of work for something that is already built into Android. Take a look at the Android Search Dialog at http://developer.android.com/guide/topics/search/search-dialog.html, and it should be very easy for you.

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

Sidebar

Related Questions

I have a dropdownlist which shows a list of countries from my database public
in my app in the first activity i have created a database which stores
I have database consists of countries and cities. First Case - Successfully done: Country
i have list of rows that user select and i want to delete them,
I have a list of countries, html, they have numeric ids and country name:
I have a plain text file which have the list of countries as follows.
I have a database table consisting of countries. In my DAO which extends HibernateDAOSupport
I have a table with a list of countries in it that I'm using
I have a class that returns a list of Regions in a database using
I have a list of countries and their area codes in a database. I

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.