I have a ListView using a custom ArrayList adapter - what's the best way to implement filtering ? Anyone have a example code to study?

前端 未结 4 2085
一个人的身影
一个人的身影 2020-12-10 00:46

Subject says it all. I have seen examples implementing a custom Filter. The Android developer docs talk about implementing a Filterable interface. Does anyone have any advic

4条回答
  •  佛祖请我去吃肉
    2020-12-10 01:22

    There are two possible ways of Resolving this

    1. Use your own Filtering Algorithm to filter the adapter(As said by others). 2. The second and much simpler method is to override the tostring method in the Custom RowItem class you might have defined

     @Override
            public String toString() {
                return name + "\n" + description;
            }
    

    where name and description are the possible text you have stored in the row items on which you want filtering

    and use the adapter.getFilter().filter(s); as such you were using it will work now because your adapter now returns a valid string to filter

提交回复
热议问题