How can I filter ListView data when typing on EditText in android

后端 未结 6 2109
醉话见心
醉话见心 2020-11-27 16:27

I have a ListView and a EditText. How can I filter ListView data when typing on EditText?

6条回答
  •  暗喜
    暗喜 (楼主)
    2020-11-27 16:51

    1) create a custom adapter for your list view and create a removeIfMatch(String s) method:

    public void removeIfMatch(String s) {
      for item in adapter:
        if item.matches(s) {
           data.removeItem(item);
           notifyDataSetChanged();
           break
        }
    }
    

    2) create a callback for when the EditText contents change

    3) invoke adapter.removeIfMatch(editText.getText())

提交回复
热议问题