0

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!

Daiwik Daarun
  • 3,804
  • 7
  • 33
  • 60

2 Answers2

4

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

ianhanniballake
  • 191,609
  • 30
  • 470
  • 443
2

I dun goofed.

SearchView

More specifically, get the SearchView as follows:

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

and then set setOnQueryTextListener

Daiwik Daarun
  • 3,804
  • 7
  • 33
  • 60