1

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?

user1906035
  • 133
  • 8

1 Answers1

2
@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.

Marian Pavel
  • 2,726
  • 8
  • 29
  • 65
  • But, if the custom search suggestions are enabled in the search, then doesn't the Android system calls the query() method to *query* the ContentProvider each time a letter is typed? – user1906035 Apr 08 '16 at 13:23
  • What do you mean by Android query the ContentProvider ? You need to handle the search from your array or what do you have and replace the actual result with what do you have. – Marian Pavel Apr 08 '16 at 13:26
  • This is in context of 'Custom Search suggestions' for Search: _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._ – user1906035 Apr 08 '16 at 13:29
  • Please see this (https://developer.android.com/guide/topics/search/adding-custom-suggestions.html#CustomContentProvider) – user1906035 Apr 08 '16 at 13:31
  • You could try this http://www.grokkingandroid.com/android-tutorial-adding-suggestions-to-search/ – Marian Pavel Apr 08 '16 at 13:37