cavallo
cavallo

Reputation: 4414

how to sort a list view on text changed android

i have been trying to filter my list view all day with referring SO solutions but was not able to do it. Hence i am pasting the code below for your reference to know exactly what i was doing.. please some one help me solve it and if possible edit my code or point out my mistake.. the list does not get filtered. thanks in advance

Upvotes: 0

Views: 292

Answers (1)

Chase
Chase

Reputation: 11191

The problem seems to be in your publishResults method. The results obtained from performFiltering are never applied to the object list inside the array adapter. The easy way to do this is to create a new ArrayAdapter with the filtered items and update your list view.

The default behavior of the array list is to filter on a prefix. If this is ok, you could just call setFilterText on the list view with the text to filter on without having to implement your own filtering.

Also, as a side, you might want to move your Filter newFilter = null; to outside your method. Otherwise you are creating the filter every time. And should not need to set constraint to the contents of etsearch inside your performFiltering method since you are invoking the filter with the text from the text watcher which should have the same string value.

Upvotes: 1

Related Questions