Logo Icon Logo
A Crowd-sourced Cookbook on Writing Great Android® Apps
GitHub logo Twitter logo OReilly Book Cover Art

Filtering a ListView based on user input

In Chapter: Other GUI Elements: Lists and Views
Author: Ian Darwin ('idarwin')
Published? false
FormatLanguage: WikiFormat


You want the contents of a ListView to update as a user types, to list only items matching the thus-far-entered portion of a name, email, etc.


There are two approaches:

1) The official approach: In your ListAdapter, override the FilterResults performFiltering() method, and in your KeyListener, call the adapter's getFilter().filter(currentText) method;

2) An unofficial approach that is less coding but also less efficient: Re-create the list contents each time the user enters a keystroke


To follow

See Also:

http://stackoverflow.com/questions/5658751/filter-list-view-from-edit-text for another example of method 1.

http://www.androidpeople.com/android-listview-searchbox-sort-items for another example of method 2.