> For the complete documentation index, see [llms.txt](https://android-course.cornellappdev.com/llms.txt). Markdown versions of documentation pages are available by appending `.md` to page URLs; this page is available as [Markdown](https://android-course.cornellappdev.com/archive/archived-native-android-textbook-pages/5.-listviews/5.4-searching-in-a-list-view.md).

# 3.4 Searching in a List View

If we wanted to search for an item within a `ListView`, we would have to somehow get input from the user which is something we can do with a specific view type.

The `EditText` will allow us to get user input we can then filter our list with.

![EditText example](/files/-MWwLri572ukAYNvdp6X)

Once we have an `EditText` we can create an `addTextChangedListener`to it to customize the behavior on such actions:

```
editText.addTextChangedListener(object : TextWatcher {
      override fun afterTextChanged(s: Editable?) {
      }
      override fun beforeTextChanged(s: CharSequence?, start: Int, count: Int, after: Int) {
      }
      override fun onTextChanged(s: CharSequence?, start: Int, before: Int, count: Int) {
      // requery/filter your adapter then set it to your listview
      }
    })
```

The above code has 3 overridden functions:

* `afterTextChanged`
  * &#x20;This method is called to notify you that, somewhere within `s`, the text has been changed.
* `beforeTextChanged`
  * &#x20;This method is called to notify you that, within `s`, the `count` characters beginning at `start` are about to be replaced by new text with length `after`.
* `onTextChanged`
  * &#x20;This method is called to notify you that, within `s`, the `count` characters beginning at `start` have just replaced old text that had length `before`.

`onTextChanged`is the method in which we will requery our adapter and then set it to our list view to change the results of what is displayed after searching; effectively searching.


---

# Agent Instructions
This documentation is published with GitBook. GitBook is the documentation platform designed so that both humans and AI agents can read, navigate, and reason over technical content effectively. Learn more at gitbook.com.

## Querying This Documentation
If you need additional information that is not directly available in this page, you can query the documentation dynamically by asking a question.

Perform an HTTP GET request on the current page URL with the `ask` query parameter, and the optional `goal` query parameter:

```
GET https://android-course.cornellappdev.com/archive/archived-native-android-textbook-pages/5.-listviews/5.4-searching-in-a-list-view.md?ask=<question>&goal=<endgoal>
```

`ask` is the immediate question: it should be specific, self-contained, and written in natural language.
`goal` is optional and describes the broader end goal you are ultimately trying to accomplish on behalf of the user. GitBook uses it to tailor the answer towards what is most useful for that goal.

The response will contain a direct answer to the question and relevant excerpts and sources from the documentation.

Use this mechanism when the answer is not explicitly present in the current page, you need clarification or additional context, or you want to retrieve related documentation sections.
