Free Shipping

Secure Payment

easy returns

24/7 support

  • Home
  • Blog
  • Custom ListView Filter with Example in Android

Custom ListView Filter with Example in Android

 July 9  | 0 Comments


It is very simple to make a ListView but a custom ListView contains so much data in a row like image, text, buttons etc. according to need of a application and if our ListView is very long then there is need to add a filter option for user to choose an item in a list easily.

To filter the Custom ListView we have to add an input field where the user can insert the keys to filter the ListView.

Methods & Classes:


getView(): To inflate the row data of ListView this method is called.

getFilter(): This method is overrided when we implement the Filterable interface and it returns the new filter.


Here we create a private class i.e ValueFilter inside our custom adapter class and extends with Filter class to perform the filter operation.

Filter has two major components i.e performFiltering(..) method and publishResults(..) method.

performFiltering() method creates a new Arraylist with filtered data.

publishResults() method is for notify data set changed.

Real Time Example:

Android gives the feature of filter option in Phone application to filter a particular name.And in various application this feature is used like in this example.

Example with Code:

Here you see How to implement filter custom ListView in Android.

These are the steps:

  1. Create a new Application FilteringCustomListViewAndroid.
  2. 2 XML Layout files are needed for it.
  3. Two String array is need to be implement.XML Layout files:
    1. activity_main.xml : add the searchview and listview inside this.


    2. list_item.xml : It shows the row data add imageview and textview inside this.

    BabyDetailsData class:

    Create a class model BabyDetailsData and implements its setter’s getters for row data of each items of ListView. i.e.

    CustomListViewAdapter class:

    As I discussed above, here we implement Filterable interface and override the getfilter() method.

    Create ValueFilter class inside it.


    MainActivity class:

    Implement SearchView.OnQueryTextListener interface and override its methods onQueryTextChange() and onQueryTextSubmit().

    Initialize SearchView:

    Add code in onCreate(){..}

    Create some code in onQueryTextChange() method :


    output 1 output 2Conclusion:

    This is the basic idea of how to filter custom ListView.It is nothing just to add the SearchView for the user to insert the keys to filter data inside the list.It is used in many application like I give the example of phone application.We can also customize the SearchView according to the need.This feature is very popular in android development.