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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 27, 20262026-05-27T06:15:17+00:00 2026-05-27T06:15:17+00:00

In my android app I want to apply a filter on the listview. Each

  • 0

In my android app I want to apply a filter on the listview. Each row of the list shows the contact name, type of contact number, contact number etc.
How can I apply the filter on the list, so when I enter the name of the person on edit text the list view must be refreshed on text change? I am using the another class to populate the list.

Here is my code.

AllContactsActivity class retrieve the contact from the phone.

public class AllContactsActivity extends ListActivity implements
            android.view.View.OnClickListener, OnItemClickListener {
        EditText sc;
        String name, phonetype;
        ImageButton favourites, contacts, keypad, recent, about;
        int arr, key;
        Cursor tcur;
        int[] typecount, count, id;
        ListView lv;
        ListViewAdapterContacts lva;
        String[] names, numbers, typeinfo, contactinfo, types;
        Integer[] sortlist;
        TreeMap<Integer, String> sorted_set;
        LinkedHashMap<Integer, String> sortedMap;
        ContentResolver tcr;
        HashMap<Integer, String> numbhashmap;
        ArrayAdapter<String> adapter = null;

        @Override
        public void onCreate(Bundle savedInstanceState) {
            super.onCreate(savedInstanceState);

            LayoutParams params = new RelativeLayout.LayoutParams(
                    LayoutParams.WRAP_CONTENT, LayoutParams.WRAP_CONTENT);
            LinearLayout mainLayout = new LinearLayout(this);
            mainLayout.setOrientation(LinearLayout.VERTICAL);
            LayoutInflater layoutInflater = getLayoutInflater();
            mainLayout.addView(layoutInflater.inflate(R.layout.allcontacts, null));
            mainLayout.addView(layoutInflater.inflate(R.layout.allbuttons, null));
            this.addContentView(mainLayout, params);

            //configureBottomMenu();
            getphones();//get the cantact number
            getContacts();//get contact name,type,id
    //names,types,number,id are populated by above two methods.

            lv = new ListView(getApplicationContext());
            lv = (ListView) findViewById(android.R.id.list);
    //ListViewAdapterContacts class is specified later in the code which populate the list view

            lva = new ListViewAdapterContacts(this, names, types, numbers, id);


            lv.setAdapter(lva);
            lv.setTextFilterEnabled(true);
            lv.setOnItemClickListener(this);

            sc=(EditText)findViewById(R.id.searchcontact);
            sc.addTextChangedListener(textwatcher);


        }// on create
        @Override
        protected void onDestroy() {
            super.onDestroy();
            sc.removeTextChangedListener(textwatcher);
        }

        private TextWatcher textwatcher = 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
                AllContactsActivity.this.lva.getFilter().filter(s.toString());
                lva.notifyDataSetChanged();

            }
        };


    }

Here is ListViewAdapterContacts.java

public class ListViewAdapterContacts extends BaseAdapter implements Filterable{

    Activity context;
    String[] names;
    String[] types;
    String[] numbers;
    int[] id;
    public ListViewAdapterContacts(Activity context, String[] names, String[] types, String[] numbers, int[] id) {
        // TODO Auto-generated constructor stub

    this.context=context;
    this.names=names;
    this.types=types;
    this.numbers=numbers;
    this.id=id;
    }

    public int getCount() {
        // TODO Auto-generated method stub 
        if(names==null){
            return 0;
        }
        else{
            return names.length;
        }
    }

    public Object getItem(int position) {
        // TODO Auto-generated method stub
        return null;
    }

    public long getItemId(int position) {
        // TODO Auto-generated method stub
        return 0;
    }

    public class viewHolder {
        TextView top;
        TextView bottom;
        TextView downside;
        TextView base;
    }

      public View getView(int position, View convertView, ViewGroup parent) {
        // TODO Auto-generated method stub
        viewHolder holder;
        if(convertView==null){

        LayoutInflater inflator=context.getLayoutInflater();
        convertView=inflator.inflate(R.layout.textviewonly,null);

        holder=new viewHolder();
        holder.top=(TextView)convertView.findViewById(R.id.toptext);
        holder.bottom=(TextView)convertView.findViewById(R.id.bottomtext);
        holder.downside=(TextView)convertView.findViewById(R.id.lowest);
        holder.base=(TextView)convertView.findViewById(R.id.baseid);
        convertView.setTag(holder);
        }else{
            holder=(viewHolder)convertView.getTag();
        }
        holder.top.setText(names[position]);
        holder.bottom.setText(types[position]);
        holder.downside.setText(numbers[position]);
        holder.base.setText(""+id[position]);


        View v=(View)convertView;
        //return convertView;
        return v; 
    }


    public Filter getFilter() {
        // TODO Auto-generated method stub
        return null;
    }
}
  • 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-27T06:15:18+00:00Added an answer on May 27, 2026 at 6:15 am

    override getFilter() and put this:

    public Filter getFilter() {
      return new MyCustomFilter();
    }
    

    of course you have to create your custom filter

    private class MyCustomFilter extends Filter {
      @Override
      protected FilterResults performFiltering(CharSequence prefix) {
        FilterResults results = new FilterResults();
        // perform your filtering. you'll need to create a new List to get the correct filtered results. then
        results.values = (your new List);
        results.count = (your new List).size();
    
        return results;
      @Override
      protected void publishResults(CharSequence constraint, FilterResults results) {
        List filtered = (ArrayList)results.values;
          // set the data of your adapter here
    
          if(results.count>0) {
            notifyDataSetChanged();
          } else {
            notifyDataSetInvalidated();
          }
      }
    }
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I'm building an Android app and I want to copy the text value of
I want my Android app to take a picture, as part of something larger
I want to update a Application on Android App Market but the problem is
I want to implement an android app which compares recorded audio files with our
I am writing an android app. I want to pass some data across the
We have an Android app and a Web Service. We want to download part
I've got an Android app which has a periodic background Service. I want this
In my android app, I'm setting an alarm that I want to occur repeatedly,
My android app has a two word app name, and the 2nd word doesn't
I have an Android app with a ListActivity in the main view. The list

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.