MaterialSearchView
MaterialSearchView copied to clipboard
history not added if searchView.setQuery(suggestion, true)
history not added if searchView.setQuery(suggestion, true)
Is this happening only when you try to use it that way? If you set the flag to false, does it work?
Also, try to do: searchView.setShouldKeepHistory(true)
as well. If this flag is false it won't save the search history.
If I submitted the query with search button on keyboard, the suggestion is added to the history list. However, if I submitted the query with searchView.setQuery(suggestion, true)
, the history list is not updated.
Ps. I have done searchView.setShouldKeepHistory(true)
.
Hm. That's weird. But I'll take a look and try to reproduce the problem. Thanks for the report!
Thanks for checking it. Different from your example:
@Override
protected void onPause()
{
super.onPause();
searchView.clearSuggestions();
}
@Override
protected void onResume()
{
super.onResume();
searchView.activityResumed();
String[] arr = getResources().getStringArray(R.array.suggestions);
searchView.addSuggestions(arr);
}
In my app, I update the suggestions based on the query:
@Override
public boolean onQueryTextChange(String newText)
{
searchView.clearSuggestions();
if (newText.length() > 0)
{
if (suggestionThread.isRunning())
suggestionThread.stop();
suggestionThread.query = newText;
suggestionThread.start();
}
return false;
}
In suggestionThread
, I add every generated suggestion by searchView.addSuggestion(suggestion)
.
Then
searchView.setOnItemClickListener((parent, v, position, id) -> {
String suggestion = searchView.getSuggestionAtPosition(position);
searchView.setQuery(suggestion, true);
});
Can I manage history by myself, e.g., add history, save and load history?