Question

My app has a twoline ListView with a custom adapter. I want to filter the listview contents with the input to a EditText. How is it possible?

lv.setAdapter(new MyCustomBaseAdapter(getActivity(),recordObjects));
//recordObjects is an ArrayList of objects 
Was it helpful?

Solution

you have to set TextWatcher to your EditText and

and then filter your data using dynamic array...

OTHER TIPS

Use the addTextChangedListener method to add a TextWatcher to your EditText. Then in your implementation of onTextChanged, add or remove the items from your ListView's adapter as appropriate.

Is this the kind of thing you wanted?

ListView lv = getListView();
            /* Gets a ListView */
            lv.setTextFilterEnabled(true);

            /* sorts the listview */
            ArrayAdapter<String> adapter = new ArrayAdapter<String>(
                    getApplicationContext(),
                    android.R.layout.simple_list_item_1,
                    result.getheadlines());
            setListAdapter(adapter);
            /*
             * gets the lisadapter from the XML and sets it equal to
             * whatever result is
             */
Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top