How could i filter the listview using baseadapter

后端 未结 5 1694
遥遥无期
遥遥无期 2020-11-28 13:03

I am trying to filter the listview but getfilter method is not working,

here is the code:

@Override
public void afterTextChanged(Editable s) {
}

@Ov         


        
5条回答
  •  [愿得一人]
    2020-11-28 13:14

    I think there is no need of getfilter() method over here

    ArrayList data;
    .
    .
    .
    Collections.sort(data, new Comparator() {
    @Override
    public int compare(YourDataModel data1, YourDataModel data2) {
          if( data1.getDistance() < data2.getDistance() )
             return 1;
          else
             return 0;
    }
    });
    .
    .
    .
    ListView lvData = (ListView) findViewById(R.id.listview1);
    MyCustomAdapter adapter = new MyCustomAdapter(this, R.layout.listview_item_row, data);
    lvData.setAdapter(adapter);
    

    and use notifydatachange method whenever you want to update it

提交回复
热议问题