Daiwik Daarun
Daiwik Daarun

Reputation: 3974

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!

Upvotes: 0

Views: 3192

Answers (2)

ianhanniballake
ianhanniballake

Reputation: 199805

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

Upvotes: 4

Daiwik Daarun
Daiwik Daarun

Reputation: 3974

I dun goofed.

SearchView

More specifically, get the SearchView as follows:

SearchView searchView = (SearchView) menu.findItem(R.id.search).getActionView();

and then set setOnQueryTextListener

Upvotes: 2

Related Questions