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 9243445
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 18, 20262026-06-18T08:48:49+00:00 2026-06-18T08:48:49+00:00

I have a custom CursorAdapter class that uses the alphabet indexer and I want

  • 0

I have a custom CursorAdapter class that uses the alphabet indexer and I want to implement filterable, but I am having some problems getting it to function correctly.

    c = db.selectData();


    lv = (ListView) findViewById(android.R.id.list);
    searchTerm = (EditText) findViewById(R.id.inputSearch);

    lv.setFastScrollEnabled(true);

    adapter = new MyCursorAdapter(getApplicationContext(), R.layout.rowlayout, c, new String[]{"_id, name, company, job_title"},
            new int[]{R.id.company, R.id.job_title, R.id.name});

    adapter.setFilterQueryProvider(new FilterQueryProvider() {
        public Cursor runQuery(CharSequence constraint) {
            // Search for states whose names begin with the specified letters.
            Cursor cursor = db.searchAttendees(constraint.toString());
            return cursor;

        }
    });

    lv.setAdapter(adapter);

    getListView().setTextFilterEnabled(true);

    searchTerm.addTextChangedListener(new TextWatcher() {

        @Override
        public void onTextChanged(CharSequence s, int start, int before, int count) {
            System.out.println("Text ["+s+"]");
            adapter.getFilter().filter(s.toString());
        }

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

        }

        @Override
        public void afterTextChanged(Editable s) {
        }
    });

  }

And this is the MyCustomAdapter class

        public class MyCursorAdapter extends CursorAdapter  implements SectionIndexer, Filterable
{

    AlphabetIndexer mAlphabetIndexer;

    public MyCursorAdapter(Context context, int simpleListItem1,
            Cursor cursor, String[] strings, int[] is)
    {
        super(context, cursor);
        mAlphabetIndexer = new AlphabetIndexer(cursor,
                cursor.getColumnIndex("name"),
                " ABCDEFGHIJKLMNOPQRTSUVWXYZ");
        mAlphabetIndexer.setCursor(cursor);//Sets a new cursor as the data set and resets the cache of indices.

    }

    /**
     * Performs a binary search or cache lookup to find the first row that matches a given section's starting letter.
     */
    @Override
    public int getPositionForSection(int sectionIndex)
    {
        return mAlphabetIndexer.getPositionForSection(sectionIndex);
    }

    /**
     * Returns the section index for a given position in the list by querying the item and comparing it with all items
     * in the section array.
     */
    @Override
    public int getSectionForPosition(int position)
    {
        return mAlphabetIndexer.getSectionForPosition(position);
    }

    /**
     * Returns the section array constructed from the alphabet provided in the constructor.
     */
    @Override
    public Object[] getSections()
    {
        return mAlphabetIndexer.getSections();
    }

    @Override
    public Cursor runQueryOnBackgroundThread(CharSequence constraint) {
        //What to do here?

    }

    /**
     * Bind an existing view to the data pointed to by cursor
     */
    @Override
    public void bindView(View view, Context context, Cursor cursor) {
        TextView name = (TextView)view.findViewById(R.id.name);
        name.setText(cursor.getString(
                cursor.getColumnIndex("name")));
        TextView company = (TextView)view.findViewById(R.id.company);
        company.setText(cursor.getString(
                cursor.getColumnIndex("company")));
        TextView jobTitle = (TextView)view.findViewById(R.id.job_title);
        jobTitle.setText(cursor.getString(
                cursor.getColumnIndex("job_title")));
    }

    /**
     * Makes a new view to hold the data pointed to by cursor.
     */
    @Override
    public View newView(Context context, Cursor cursor, ViewGroup parent) {
        LayoutInflater inflater = LayoutInflater.from(context);
        View newView = inflater.inflate(
                R.layout.attendee_item_row, parent, false);
        return newView;
    }

I know I need to use runQueryOnBackgroundThread but I don’t know what I am meant to implement in this method. Could someone help me here? Or point me in the direction of some examples?

Thanks!

  • 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-06-18T08:48:50+00:00Added an answer on June 18, 2026 at 8:48 am

    I know I need to use runQueryOnBackgroundThread but I don’t know what
    I am meant to implement in this method.

    If you set a FilterQueryProvider on the CursorAdapter then you don’t override that method(which by default calls the runQuery method of the FilterQueryProvider). When you want to filter the adapter simply call the getFilter().filter(constraint) method giving it the new constraint.

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

Sidebar

Related Questions

I have custom classes that I currently instantiate within App.xaml as resources. I want
I have a custom CursorAdapter that is taking items from a database and displaying
I have a list of adverts that is being populated by a custom cursoradapter.
I have a custom CursorAdapter and it looks like : public class LabelAdapter extends
I have a ListView of items with checkboxes. I have a custom CursorAdapter that
I have a nicely working custom CursorAdapter with customized ListView. This view allows the
I have custom event that has several different subscribers who will all use the
I have custom gallery. Gallery represents items that are frame layout. There are one
I have custom component that I can place in my layout file (XML) for
I have custom subclass of a UITableViewCell with some constraints set. Problem is when

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.