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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 18, 20262026-06-18T04:15:47+00:00 2026-06-18T04:15:47+00:00

I have created a list view in android and I want to add edit

  • 0

I have created a list view in android and I want to add edit text above the list and when the user enter text the list will be filtered according to user input

can anyone tell me please if there is a way to filter the list adapter in android ?

  • 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-18T04:15:49+00:00Added an answer on June 18, 2026 at 4:15 am

    Add an EditText on top of your listview in its .xml layout file.
    And in your activity/fragment..

    lv = (ListView) findViewById(R.id.list_view);
        inputSearch = (EditText) findViewById(R.id.inputSearch);
    
    // Adding items to listview
    adapter = new ArrayAdapter<String>(this, R.layout.list_item, R.id.product_name,    products);
    lv.setAdapter(adapter);       
    inputSearch.addTextChangedListener(new TextWatcher() {
    
        @Override
        public void onTextChanged(CharSequence cs, int arg1, int arg2, int arg3) {
            // When user changed the Text
            MainActivity.this.adapter.getFilter().filter(cs);
        }
    
        @Override
        public void beforeTextChanged(CharSequence arg0, int arg1, int arg2, int arg3) { }
    
        @Override
        public void afterTextChanged(Editable arg0) {}
    });
    

    The basic here is to add an OnTextChangeListener to your edit text and inside its callback method apply filter to your listview’s adapter.

    EDIT

    To get filter to your custom BaseAdapter you”ll need to implement Filterable interface.

    class CustomAdapter extends BaseAdapter implements Filterable {
    
        public View getView(){
        ...
        }
        public Integer getCount()
        {
        ...
        }
    
        @Override
        public Filter getFilter() {
    
            Filter filter = new Filter() {
    
                @SuppressWarnings("unchecked")
                @Override
                protected void publishResults(CharSequence constraint, FilterResults results) {
    
                    arrayListNames = (List<String>) results.values;
                    notifyDataSetChanged();
                }
    
                @Override
                protected FilterResults performFiltering(CharSequence constraint) {
    
                    FilterResults results = new FilterResults();
                    ArrayList<String> FilteredArrayNames = new ArrayList<String>();
    
                    // perform your search here using the searchConstraint String.
    
                    constraint = constraint.toString().toLowerCase();
                    for (int i = 0; i < mDatabaseOfNames.size(); i++) {
                        String dataNames = mDatabaseOfNames.get(i);
                        if (dataNames.toLowerCase().startsWith(constraint.toString()))  {
                            FilteredArrayNames.add(dataNames);
                        }
                    }
    
                    results.count = FilteredArrayNames.size();
                    results.values = FilteredArrayNames;
                    Log.e("VALUES", results.values.toString());
    
                    return results;
                }
            };
    
            return filter;
        }
    }
    

    Inside performFiltering() you need to do actual comparison of the search query to values in your database. It will pass its result to publishResults() method.

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

Sidebar

Related Questions

I have created a list of contact's in user phone, now i want to
I want to use a list view and I have created my own layout
I have a custom list View that contains 7 text views..I have created a
I have created a list view that displays the names and dates of items
I have created a custom list view, each row has it's own custom selector,
I have created navigaton view using Sencha touch 2. Navigation view has list component
I have created a TableView(Grouped Table View). And I can list the items in
Hi I have created Expandible list view using BaseExpandableListAdapter. If i scroll the list
I have created a dialog which contains a list view. The onclicklistener for the
Actually I have created a custom ListView . I want to add items to

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.