How to make a custom ListView filterable

Put your problem here if it does not fit any of the other categories.

How to make a custom ListView filterable

Postby PaulFake » Mon Oct 12, 2009 11:43 pm

Hi,

I have a ListView whose rows contain three TextViews. I want to be able to filter my ListView using setFilterText(), and have it filter based on what's in only the topmost TextView. Android's documentation suggests implementing the Filterable interface, but there isn't really much else about it...If anyone has done this and would like to share, I'd be more than pleased.

-Paul
PaulFake
Junior Developer
Junior Developer
 
Posts: 21
Joined: Wed Aug 26, 2009 1:05 am

Top

Postby wiederke » Tue Oct 13, 2009 12:15 pm

Hi,

your ListView has to implement Filterable interface first. Then extend the class android.widget.Filter and implement your own filter in performFiltering() and publish your result publishResults(). Have a look at the code of the ArrayAdapter. They implement the Filter as a private inner class, so it is easy to understand what they are doing. (Even if I don't like the solution in ArrayAdapter).


Bye,

Torsten
wiederke
Experienced Developer
Experienced Developer
 
Posts: 72
Joined: Mon Mar 02, 2009 6:46 pm
Location: Germany

Postby PaulFake » Fri Oct 16, 2009 4:43 am

Thanks, I ended up doing the same type of thing that ArrayAdapter does, and it works.
PaulFake
Junior Developer
Junior Developer
 
Posts: 21
Joined: Wed Aug 26, 2009 1:05 am

Top

Return to Other Coding-Problems

Who is online

Users browsing this forum: Google [Bot] and 25 guests