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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 1, 20262026-06-01T08:17:19+00:00 2026-06-01T08:17:19+00:00

I have list view and its adapter stored as global variables. I am not

  • 0

I have list view and its adapter stored as global variables. I am not creating my list by extending ListActivity. My code is as follows:

public void onCreate(Bundle...) {
    mListView = (ListView) findViewById(R.id.listview1);
    //setting my custom array adapter...works fine.
    //also my custom adapter implements Filterable interface
    mListView.setAdapter(...) 
    mListView.setTextFilterEnabled(true);

    //My edit text where I enter my query
    mSearchEditText = (EditText) findViewById(R.id.searchEditText);
    mSearchEditText.addTextChangedLIstener(myListener);
}

private TextWatcher myListener = new TextWatcher () {

    public void onTextChanged(CharSequence s, int start, int before, int count) {
        if (s == null || s.length() == 0) {
            mListView.clearTextFilter();
        }
        else {
            mListView.setFilterText(s.toString());
        }
    }
    ...
    ...
}

My problem is when I enter my string in edit text, it gives me correct no of available search items (only number) in my list but not the items itself.

For example if my list has items aa, bb, cc, dd, ff, ee, ee

So if I search for ee, my result will be aa, bb and not the ee, ee. And if I search cc, my filter list will show aa only.

Can anyone help me on this?

  • 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-01T08:17:21+00:00Added an answer on June 1, 2026 at 8:17 am

    I have a working example, try this:

    filterEditText = (EditText)findViewById(R.id.filter);
    filterEditText.addTextChangedListener(filterTextWatcher);
    
    TextWatcher filterTextWatcher = new TextWatcher() {
    
            public void beforeTextChanged(CharSequence s, int start, int count,int after) {  
    
            }  
            public void onTextChanged(CharSequence s, int start, int before,int count) {  
                adapter.getFilter().filter(s);
            }
    
            @Override
            public void afterTextChanged(Editable s) {
                // TODO Auto-generated method stub              
            }  
        };
    

    The adapter must implements Filterable

                @Override
                public Filter getFilter() {
    //              Filter filter = null;
    
                    if(filter == null)
                        filter = new CheeseFilter();
                    return filter;
                }
    

    And the filter class:

            public class CheeseFilter extends Filter {
    
                @Override
                protected FilterResults performFiltering(CharSequence constraint) {
                    // TODO Auto-generated method stub
    
                    constraint = constraint.toString().toLowerCase();
    
                    FilterResults newFilterResults = new FilterResults();
    
                    if (constraint != null && constraint.length() > 0) {
    
    
                        ArrayList<String> auxData = new ArrayList<String>();
    
                        for (int i = 0; i < data.size(); i++) {
                            if (data.get(i).toLowerCase().contains(constraint))
                                auxData.add(data.get(i));
                        }
    
                        newFilterResults.count = auxData.size();
                        newFilterResults.values = auxData;
                    } else {
    
                        newFilterResults.count = data.size();
                        newFilterResults.values = data;
                    }
    
                    return newFilterResults;
                }
    
                @Override
                protected void publishResults(CharSequence constraint, FilterResults results) {
    
                    ArrayList<String> resultData = new ArrayList<String>();
    
                    resultData = (ArrayList<String>) results.values;
    
                    EfficientAdapter adapter = new EfficientAdapter(context, resultData);
                    list.setAdapter(adapter);
    
    //              notifyDataSetChanged();
                }
    
            }
    

    You can check this post for more info:

    Filter expandableList

    Filter ListView

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

Sidebar

Related Questions

i have implemented a list view its working fine but when i click on
In my Android application, I have a simple list view with adapter. There's a
I have implemented a custom list view which looks like the twitter timeline. adapter
i have created a My custom listActivty by extending ListActivity like this. public class
I have created a custom list view, each row has it's own custom selector,
In my application, I have list view. Selecting another item in it, triggers an
I have a list view filled with data. I set up a context menu
I have a list view with over 100 items. Each of these items show
I have a list view contains 100+ rows. every time the user opens the
I have a ListView which uses a CursorAdatper as its adapter. I would like

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.