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

后端 未结 6 2111
醉话见心
醉话见心 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:55

    You can use:

    http://developer.android.com/reference/android/widget/TextView.html

    addTextChangedListener( TextWatcher watcher )

    to figure out when the textview was changed. I believe it should be called everytime a letter is added or removed.

    Then update your list adapter to dislplay the new items by either:

    1. creating a new list adapter and populating it with the items that satisfy the filter or
    2. having a subclass of the BaseAdapter to accept your filter and call notifyDataSetChanged() after it has finished removing the items you no longer want

    http://developer.android.com/reference/android/widget/BaseAdapter.html

提交回复
热议问题