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

The Archive Base Latest Questions

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

I have recently added a bounty to this SO question , but realise the

  • 0

I have recently added a bounty to this SO question, but realise the original question asks for a SimpleAdapter and not an ArrayAdapter. So, this question relates to the ArrayAdapter:

I would like to be able to filter an ArrayAdapter in a ListView using multiple search terms. For example, if my list contains the following items:

a thing
another thing
a different thing
nothing
some thing

If I search for ‘thing’ then all the terms should be returned in the filter results. This is normal behaviour that can be accomplished using the following code:

    private TextWatcher filterTextWatcher = new TextWatcher() {

    public void onTextChanged(CharSequence s, int start, int before, int count) {
        // TODO Auto-generated method stub

    }

    public void beforeTextChanged(CharSequence s, int start, int count,
            int after) {
        // TODO Auto-generated method stub

    }

    public void afterTextChanged(Editable s) {
        // TODO Auto-generated method stub
        myAdapter.getFilter().filter(s.toString());
    }
};

However; if I enter the search phrase ‘a thing‘, I expect the following results to be shown:

a thing
another thing
a different thing

In fact, all I get returned in the result ‘a thing‘. Since the filter is looking for the entire string, it treats the space as a part of the search term. Essentially, what I’m asking is how do I filter the list not by one specific string, but by multiple search terms, each separated by spaces? So long as each of the search terms appear at least once in the item, then that item should be returned in the result.

Similar questions seem to have been asked before on SO (for example, see the link at the top of this post, which concerns SimpleAdapters), but nowhere have I found an actual way to accomplish this. I suppose the answer would involve separating the search phrase into individual strings, delimited by the space character, and then running the search multiple times on each string, and only returning the results which match for all of the iterations…

  • 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-14T08:53:20+00:00Added an answer on June 14, 2026 at 8:53 am

    Unfortunately ArrayAdapter and other built-in adapters don’t allow you to change their existing filters. There is no setFilter() method in the API… You must create a custom adapter that performs the same functions as ArrayAdapter.

    To do this: simply cut & paste ArrayAdapter’s source code into a new class in your project. Then find the Filter at the bottom. Inside performFiltering() we’ll make a few changes. Find the if-else block marked with the following comment and replace that code block with this:

    // First match against the whole, non-splitted value
    if (valueText.startsWith(prefixString)) {
        newValues.add(value);
    } else {
        // Break the prefix into "words"
        final String[] prefixes = prefixString.split(" ");
        final int prefixCount = prefixes.length;
    
        int loc;
        // Find the first "word" in prefix
        if(valueText.startsWith(prefixes[0]) || (loc = valueText.indexOf(' ' + prefixes[0])) > -1)
            loc = valueText.indexOf(prefixes[0]);
    
        // Find the following "words" in order
        for (int j = 1; j < prefixCount && loc > -1; j++) 
            loc = valueText.indexOf(' ' + prefixes[j], loc + 2);
    
        // If every "word" is in this row, add it to the results
        if(loc > -1) 
            newValues.add(value);
    }
    

    That’s it. We only had to change the section of code above to meet your requirements, but we have to copy the entire adapter into a class since there is no other way to makes these changes.

    (PS Since you’ve already created a new class, you might as well optimize getView() to suit you needs. The generic method is slower than it needs to be for a custom class.)

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

Sidebar

Related Questions

I have recently added a new project to Git using Eclipse, but do not
I am a beginner and have a basic question. I recently added this code
I have some code here. I recently added this root_id parameter. The goal of
I have recently added OpenID login to my website. But I don't know how
i have recently come to this error , i search a lot but i
Spotify recently added a feature where the taskbar icon would have a red iOS-style
I recently added a script requiring vim-ruby, The question I have is similar to:
Google Plus recently added events, but have they added API methods to access the
Not even sure if this is feasible, but here's the use case: I have
I recently added Android's LVL copy protection to my app, and the results have

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.