Filter a list when text is change in a List

EditText inputSearch = (EditText)getView().findViewById(R.id.inputGroupSearch);
    inputSearch.addTextChangedListener(new TextWatcher() {
 
        @Override
        public void onTextChanged(CharSequence cs, int arg1, int arg2, int arg3) {
            // When user changed the Text           Myadapter.getFilter().filter(cs);
        }})

but this code is not running

Last updated:3/20/2015 3:30:19 AM

1 Answers

Manoj Pandey
Manoj Pandey

Add following code for filter list on edittext type

editText = (EditText) view.findViewById(R.id.filerText);

     editText.addTextChangedListener(new TextWatcher() {  

         @Override

         public void onTextChanged(CharSequence cs, int arg1, int arg2, int arg3) {

            YourCustomAdapter Myadapter= (YourCustomAdapter) getListAdapter();

                  Myadapter.getFilter().filter(cs);

         } 

         @Override

         public void beforeTextChanged(CharSequence arg0, int arg1, int arg2, int arg3) { } 

         @Override

         public void afterTextChanged(Editable arg0) {}

     });


 

Answer