user1906035
user1906035

Reputation: 133

Which method is called when query-text changes in SearchView, while both Search suggestions and OnQueryTextListener interface are implemented?

In the Android Documentation, in topic 'Adding Custom Suggestions' for Search feature, it says that:

When the user starts typing into the search dialog or search widget, the system queries your content provider for suggestions by calling query() each time a letter is typed.

Source: https://developer.android.com/guide/topics/search/adding-custom-suggestions.html#CustomContentProvider

Also, in the documentation on SearchView.OnQueryTextListener interface (which is supposed to provide Callbacks for changes to the query text), the method onQueryTextChange (String newText)is

Called when the query text is changed by the user.

Source: https://developer.android.com/reference/android/widget/SearchView.OnQueryTextListener.html#onQueryTextChange%28java.lang.String%29

I am trying to implement SearchView.OnQueryTextListenerto make sure that the Loader is restarted in the call to onQueryTextChange (String newText) to deal with the "next" query because Android does not execute the query again when the query-text changes after first search(i.e. once a search has already been performed once).

My question is: If both Custom Search suggestions and SearchView.OnQueryTextListener interface have been implemented, then, which of these two methods query() (called by the Android system) and onQueryTextChange (String newText) (callback method) is called when the query text changes in SearchView widget?

Upvotes: 1

Views: 1183

Answers (1)

Marian Pavel
Marian Pavel

Reputation: 2876

@Override
public boolean onQueryTextChange(String query) {
    return false;
}

@Override
public boolean onQueryTextSubmit(String query) {
    return false;
}

Note: Your activity should implement SearchView.OnQueryTextListener

To answer to your question, onQueryTextChange() is called when the user type or delete a letter and onQueryTextSubmit() it's called when the user is pressing the done button on keyboard. You can easily check this by adding some logcat.

Upvotes: 2

Related Questions