Searching a listview with custom adapter
-
11-12-2019 - |
Domanda
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
Soluzione
you have to set TextWatcher to your EditText
and
and then filter your data using dynamic array...
Altri suggerimenti
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
*/
Autorizzato sotto: CC-BY-SA insieme a attribuzione
Non affiliato a StackOverflow