As you can see in my previous post about ListView filtering in Android (How to create filter for ListView items in Android.) creating filter is pretty simple if you’re have list with Strings.

Here I show you how to create filter for your custom adapter with complex objects. Here the screenshot of sample application:

How to create filter for ListView items in Android. Part-2. List with custom adapter.

How to create filter for ListView items in Android. Part-2. List with custom adapter.

Here is updated version of this (How to create filter for ListView items in Android.) application.

In the list of countries you also can see population and area of the country.

Please look at Country class:

Note: Take a look at toString() method. This is main thing. This is method used while filtering.

Adapter for Countries list. Here is nothing new:

And Activity. Take a look at TextWatcher:

That’s all.

Download it from github

Leave a Reply

Your email address will not be published. Required fields are marked *

This site uses Akismet to reduce spam. Learn how your comment data is processed.