Search code examples
androidandroid-edittexttextwatcherandroid-search

How to add TextWatcher to Search Widget


I want to have a 'live' search using the Android Search Widget. In other words, for each letter the user types I want a search to be performed. I know I will be using AsyncTask to retrieve the results, but I am unsure how to get the continuous series of queries needed.

Right now I can only get a search query when the user hits Go on the keyboard. If this were an EditText, I would simply add a TextWatcher to detect changes, but I do not know what to do for the Search Widget.

I have looked into Searchable Configuration, and Setting up the Search on the Android development page but cannot find what I am looking for. Links and tips are appreciated!


Solution

  • You want to add a OnQueryTextListener to your SearchView via setOnQueryTextListener(), which onQueryTextChange is called every time the input string changes.