Custom filtering for Custom ArrayAdapter in ListView

前端 未结 4 2130
小鲜肉
小鲜肉 2021-01-16 03:58

i write a own ArrayAdapter like this one:

public class PoiListAdapter extends ArrayAdapter implements Filterable {

    private Context context;
          


        
4条回答
  •  刺人心
    刺人心 (楼主)
    2021-01-16 04:40

    @JavaNullPointer : I was having the same problem as you did. I tried to implement the solutions provided here but was having different kinds of problem.. after thinking for a while, I assumed that the default Filter might be using toString() method of the object to filter... this turned to me right. It saved me a lot of hassle..

    reading at your codes, I believe you want to filter by the name field of Poi class. if so, then the quick solution would be SOLUTION:

    public class Poi{
    
    //your constructors and methods
    
    @Override
    public String toString(){
       return getName(); 
    }
    

提交回复
热议问题