Android Filtering List

Additional

Language
Java
Version
N/A
Created
Oct 1, 2014
Updated
Oct 4, 2014 (Retired)
Owner
aguilarguisado
Contributors
aguilarguisado
juaagugui
2
Activity
Badge
Generate
Download
Source code

Advertisement

Android Filtering List

Android Filtering List

With this component you can filter ListViews with adapters different from ArrayAdapter. Main features are:

  • Filter ListViews with custom filters.
  • Set different filters depending on UI state and events (clicks on buttons, checkbox buttons etc.)
  • Change filters dynamically depending on events.

Version

  • Version 1.0

How-to use this code

###Implementation

  • Create a new ListFilter which implements IFilteredListListener and IFilterableItem and define the required methods:

     public void onSearchResult(List<T> objects);
    

onSearchResult links filtered objects with the original list in the array adapter. This will be called every time the filter changes.

 public String getStringForFilter(T item);

getStringForFilter extracts the String value of T (as generic Object). In the sample, depending on the checkbox checked, with filter for their title, or their description.

Advice: Make sure that you are filtering texts that are being displayed in the UI, for a good user experience.

###Use

Full code is in the sample.

  • Define a ListView with an adapter which implements the interfaces defined above, and code the two required methods.

  • Define a TextWatcher for an EditText (from the layout)to filter the list.

  • If you want to change the filter dynamically, you must telling the ListFilter the event calling the method

      filterTypeChanged()
    

###TODO

  • Improve performance for ListFilter when the filter changes.
  • Make the sample with ViewHolders/CacheHolders for the ListView

License

Contact

Developer/Company