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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 27, 20262026-05-27T21:55:06+00:00 2026-05-27T21:55:06+00:00

I m developing app where there is list and above edit text,the moment i

  • 0

I m developing app where there is list and above edit text,the moment i will type something in editText i should get the result matching for the typed word.bt i cant get the result,Plz tell where am i making mistake ? Below are my Activity and Adapter.

**Activity**

public class ListFilterActivity extends ListActivity{

    ListView list;
    @Override
    protected void onCreate(Bundle savedInstanceState) {    
        super.onCreate(savedInstanceState);
        setContentView(R.layout.list_filter);   

        list = getListView();
        list.isTextFilterEnabled();

//      final ArrayAdapter<String> adapter = new ArrayAdapter<String>(this,
//                android.R.layout.simple_list_item_1, android.R.id.text1,
//                getModel());
        final CustomAdapter adapter = new CustomAdapter(ListFilterActivity.this, getModel());
        setListAdapter(adapter);
        EditText filterEditText = (EditText) findViewById(R.id.filterText);
        filterEditText.addTextChangedListener(new TextWatcher() {

            public void onTextChanged(CharSequence s, int start, int before,
                    int count) {
                adapter.getFilter().filter(s.toString());
            }

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

            public void afterTextChanged(Editable s) {
            }
        });
    }

    private ArrayList<String> getModel() {
        ArrayList<String> list = new ArrayList<String>();
        list.add("Linux");
        list.add("Windows7");
        list.add("Suse");
        list.add("Eclipse");
        list.add("Ubuntu");
        list.add("Solaris");
        list.add("Android");
        list.add("Ayes");
        list.add("iPhone");
        return list;
    }



}

Adapter***

    public class CustomAdapter extends ArrayAdapter<String> {
        private final Context context;
        private final ArrayList<String> names;
        private LayoutInflater mInflater;
        private TextView txt;

        public CustomAdapter(Context context, ArrayList<String> names) {
            super(context, R.layout.row, names);
            this.context = context;
            this.names = names;
            mInflater =  LayoutInflater.from(context);
        }

public Filter getFilter() {     
        if(newFilter == null) {
            newFilter = new Filter() {
                @Override
                protected void publishResults(CharSequence constraint, FilterResults results) {
                    // TODO Auto-generated method stub
                    Log.d("TAG", "publishResults");
                    notifyDataSetChanged();
                }
                @Override
                protected FilterResults performFiltering(CharSequence prefix) {             

                    FilterResults results = new FilterResults();
                    ArrayList<String> i = new ArrayList<String>();

                    if (prefix!= null && prefix.toString().length() > 0) {

                        for (int index = 0; index < names.size(); index++) {
                            String si = names.get(index);
                            if(si.compareTo(prefix.toString()) == 0){
                                i.add(si);  
                            }
                        }
                        results.values = i;
                        results.count = i.size();                   
                    }
                    else{
                        synchronized (names){
                            results.values = names;
                            results.count = names.size();
                        }
                    }

                    return results;
                }

            };
        }
            //    Log.d("TAG", "end getFilter");
        return newFilter;
    }
@Override
    public String getItem(int position) {    
        return super.getItem(position);
    }

    @Override
    public int getCount() {    
        return super.getCount();
    }

        @Override
        public View getView(int position, View convertView, ViewGroup parent) {
            View rowView  = convertView;
            if(rowView == null) {       
                rowView = mInflater.inflate(R.layout.row, null);
                txt = (TextView)rowView.findViewById(R.id.text1);
            }
            else {
                rowView.getTag();
            }
            txt.setText(names.get(position));

            return rowView;
        }
    }

plz help me out….

  • 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-27T21:55:07+00:00Added an answer on May 27, 2026 at 9:55 pm

    You need to implement Filterable to your Adapter Class and Override getFilter()

    Checkout this complete example for Filtering custom Adapter.

    UPDATE:

          public class ListFilterActivity extends ListActivity {
    
                    private List<String> list = new ArrayList<String>();
                    List<String> mOriginalValues;
    
                    @Override
                    public void onCreate(Bundle savedInstanceState) {
                        super.onCreate(savedInstanceState);
                        setContentView(R.layout.main);
    
                        final MyAdapter adapter = new MyAdapter(this, getModel());
                        setListAdapter(adapter);
    
                        EditText filterEditText = (EditText) findViewById(R.id.filterText);
    
                        // Add Text Change Listener to EditText
                        filterEditText.addTextChangedListener(new TextWatcher() {
    
                            @Override
                            public void onTextChanged(CharSequence s, int start, int before, int count) {
                                // Call back the Adapter with current character to Filter
                                adapter.getFilter().filter(s.toString());
                            }
    
                            @Override
                            public void beforeTextChanged(CharSequence s, int start, int count,int after) {
                            }
    
                            @Override
                            public void afterTextChanged(Editable s) {
                            }
                        });
                    }
    
                    private List<String> getModel() {
                        list.add("Linux");
                        list.add("Windows7");
                        list.add("Suse");
                        list.add("Eclipse");
                        list.add("Ubuntu");
                        list.add("Solaris");
                        list.add("Android");
                        list.add("iPhone");
                        list.add("Windows XP");
                        return list;
                    }
    
        // Adapter Class            
        public class MyAdapter extends BaseAdapter implements Filterable {
    
                    List<String> arrayList;      
                    List<String> mOriginalValues; // Original Values
                    LayoutInflater inflater;
    
                    public MyAdapter(Context context, List<String> arrayList) {
                        this.arrayList = arrayList;
                        inflater = LayoutInflater.from(context);
                    }
    
                    @Override
                    public int getCount() {
                        return arrayList.size();
                    }
    
                    @Override
                    public Object getItem(int position) {
                        return arrayList.get(position);
                    }
    
                    @Override
                    public long getItemId(int position) {
                        return position;
                    }
    
                    private class ViewHolder {
                        TextView textView;
                    }
    
                    @Override
                    public View getView(int position, View convertView, ViewGroup parent) {
    
                        ViewHolder holder = null;
    
                        if (convertView == null) {
    
                            holder = new ViewHolder();
                            convertView = inflater.inflate(R.layout.row, null);
                            holder.textView = (TextView) convertView
                                    .findViewById(R.id.textview);
                            convertView.setTag(holder);
                        } else {
                            holder = (ViewHolder) convertView.getTag();
                        }
                        holder.textView.setText(arrayList.get(position));
                        return convertView;
                    }
    
                    @Override
                    public Filter getFilter() {
                        Filter filter = new Filter() {
    
                            @SuppressWarnings("unchecked")
                            @Override
                            protected void publishResults(CharSequence constraint,FilterResults results) {
    
                                arrayList = (List<String>) results.values; // has the filtered values
                                notifyDataSetChanged();  // notifies the data with new filtered values
                            }
    
                            @Override
                            protected FilterResults performFiltering(CharSequence constraint) {
                                FilterResults results = new FilterResults();        // Holds the results of a filtering operation in values
                                List<String> FilteredArrList = new ArrayList<String>();
    
                                if (mOriginalValues == null) {
                                    mOriginalValues = new ArrayList<String>(arrayList); // saves the original data in mOriginalValues
                                }
    
                                /********
                                 * 
                                 *  If constraint(CharSequence that is received) is null returns the mOriginalValues(Original) values
                                 *  else does the Filtering and returns FilteredArrList(Filtered)  
                                 *
                                 ********/
                                if (constraint == null || constraint.length() == 0) {
    
                                    // set the Original result to return  
                                    results.count = mOriginalValues.size();
                                    results.values = mOriginalValues;
                                } else {
                                    constraint = constraint.toString().toLowerCase();
                                    for (int i = 0; i < mOriginalValues.size(); i++) {
                                        String data = mOriginalValues.get(i);
                                        if (data.toLowerCase().contains(constraint.toString())) {
                                            FilteredArrList.add(data);
                                        }
                                    }
                                    // set the Filtered result to return
                                    results.count = FilteredArrList.size();
                                    results.values = FilteredArrList;
                                }
                                return results;
                            }
                        };
                        return filter;
                    }
                }
            }
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

When developing an app that will listen on a TCP/IP port, how should one
I'm considering developing an app for Google App Engine, which should not get too
good day! im developing an app in c++ and winpcap that will list all
I am developing an app for Windows Mobile 6 and there is a CameraCaptureDialog
I'm developing a Grails App. I have about 20 Controllers right now and there
I am developing native iPhone app. I have one requirement that, there are 5
I'm developing software on google app engine. I'm using the webapp framework. is there
im developing an app for the iphone and im able to get a video
I have been developing some Django app and there's some duplicated code for different
I'm currently developing an app that will allow the user to choose an app

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.