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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 15, 20262026-06-15T17:52:29+00:00 2026-06-15T17:52:29+00:00

I have been banging my head against this one for two days on and

  • 0

I have been banging my head against this one for two days on and off.

I tried to use getfilter.filter() but it didn’t work. so I created this code to search a list. it works but when I delete some letters the list gets stuck at the last result and never updates.

eg list: hello, hi, han, solo

when i type ‘h’ then hello, hi, and han show up.

when i add an ‘e’ so thats its ‘he’ only hello shows

when i delete the e, han and hi do not come up again.

private TextWatcher filterTextWatcher = new TextWatcher() {
     final ArrayList<String> finalItems = mItems;
    @Override
    public void afterTextChanged(Editable s) {
    }

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



    @Override
    public void onTextChanged(CharSequence s, int start, int before,
            int count) {
        ArrayList<String> searchedItems = retainsSearched(mItems, s.toString());
        adapter.clear();
        for (int i = 0; i < searchedItems.size(); i++) {
            adapter.add(searchedItems.get(i));
        }
        adapter.notifyDataSetChanged();
    }

};

public  ArrayList<String> retainsSearched(ArrayList<String> mItems2, String term) {
    ArrayList<String> stations = new ArrayList<String>();
    for (int i = 0; i < mItems2.size(); i++) {
        if (mItems2.get(i).toLowerCase().startsWith(term.toLowerCase())) {
            stations.add(mItems2.get(i));
        }
    }
    return stations;
}
  • 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-15T17:52:30+00:00Added an answer on June 15, 2026 at 5:52 pm

    when i type ‘h’ then hello, hi, and han show up. when i add an ‘e’ so
    thats its ‘he’ only hello shows when i delete the e, han and hi do not
    come up again.

    That is most likely happening because the mItems list that you use in the TextWatcher is the list that is backing your adapter so by modifying it(when filtering and clearing/re adding items in the adapter) you always reduce the number of items available in the adapter, the items that you “see” each time you filter the list.

    Instead try to make a copy of your initial items(mItems list) in the adapter and always do the filtering by testing the items in that copy(but don’t modify it, just add the matched items to the adapter).

    Again, you should use the getFilter() method.

    Edit:

    ArrayList<String> searchedItems = retainsSearched(s.toString()); 
    // ...
    
    public  ArrayList<String> retainsSearched(ArrayList<String term) {
        ArrayList<String> stations = new ArrayList<String>();
        for (int i = 0; i < copyList.size(); i++) {
            if (copyList.get(i).toLowerCase().startsWith(term.toLowerCase())) {
                stations.add(copyList.get(i));
            }
        }
    }
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I've been banging my head against this one for two days now and finally
I've been banging my head against the wall with this one. I have a
I've been banging my head against this for the past two days and can't
I've been banging my head against this for too long. I have two ViewControllers
I have been banging my head against the wall on this one, for some
I have been banging my head against this for 2 days solid now and
Okay, I've been banging my head against the wall with this one. I have
I have been banging my head against this one for a while now and
I have been banging my head against this problem for days, and searched exhaustively
I've been banging my head against the wall on this one. I have a

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.