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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 17, 20262026-05-17T14:56:49+00:00 2026-05-17T14:56:49+00:00

private class NameFilter extends Filter { @Override protected FilterResults performFiltering(CharSequence constraint) { constraint =

  • 0
        private class NameFilter extends Filter
    {

        @Override
        protected FilterResults performFiltering(CharSequence constraint) {

            constraint = constraint.toString().toLowerCase();
            FilterResults result = new FilterResults();
            if(constraint != null && constraint.toString().length() > 0)
            {
                ArrayList<Order> filt = new ArrayList<Order>();
                ArrayList<Order> lItems = new ArrayList<Order>();
                synchronized (this)
                {
                    lItems.addAll(items);
                }
                for(int i = 0, l = lItems.size(); i < l; i++)
                {
                    Order m = lItems.get(i);
                    if(m.getOrderTitle().toLowerCase().contains(constraint)
                            || m.getOrderTime().toLowerCase().contains(constraint) ||
                            m.getOrderPrice().toLowerCase().contains(constraint))
                        filt.add(m);                     
                }
                result.count = filt.size();
                result.values = filt;

            }
            else
            {
                synchronized(this)
                {
                    result.values = items;
                    result.count = items.size();
                }
            }
            return result;
        }

        @SuppressWarnings("unchecked")
        @Override
        protected void publishResults(CharSequence constraint, FilterResults results) {

            filtered = (ArrayList<Order>)results.values;
            adapter.notifyDataSetChanged();
            adapter.clear();
            if(!constraint.equals("")){
            for(int i = 0; i < filtered.size(); i++){
                adapter.add(filtered.get(i));
                adapter.setId(i, filtered.get(i).getOrderId());
            }
            }

            else {
                if(orders!=null){
                 for(int i = 0; i < orders.size(); i++){
                adapter.add(orders.get(i));
                adapter.setId(i, orders.get(i).getOrderId());
                 }
                }
            }

        }

    }

The items in the ListView comes from an AsyncTask. When the AsyncTask is running I want it to stop adding non-matching items. For now, if it had loaded 5 items and I search with a specified String, then when the AsyncTask continues loading items it adds automatically Orders to the ListView, even if there isn’t a match.

How can I fix this?

Thanks in advance and tell me if the question is unclear!

  • 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-17T14:56:49+00:00Added an answer on May 17, 2026 at 2:56 pm

    According to your earlier question(s) here on SO, you can check in onProgressUpdate if your EditText is empty or not. If it contains some text, then filter it at that point.

    @Override
    protected void onProgressUpdate(Integer... i) { 
    
       CharSequence cs = yourEditText.getText().toString(); //Get text
       if(!cs.equals("")){ //Check if "cs" contains text
          adapter.add(orders.get(i[0])); //Add it to the adapter, then...    
          adapter.getFilter().filter(cs); //..do your filtering, and...
          adapter.notifyDataSetChanged(); //...update your View
       }
       else { //Otherwise, just add the order to your adapter..
           adapter.add(orders.get(i[0])); 
       }
    
    }
    

    We always add all orders (even if the EditText contains information) to make sure that all orders show up when EditText is empty.

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

Sidebar

Related Questions

No related questions found

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.