MaterialSearchView icon indicating copy to clipboard operation
MaterialSearchView copied to clipboard

history not added if searchView.setQuery(suggestion, true)

Open chaocharleswang opened this issue 5 years ago • 5 comments

history not added if searchView.setQuery(suggestion, true)

chaocharleswang avatar May 27 '19 16:05 chaocharleswang

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.

Mauker1 avatar May 27 '19 16:05 Mauker1

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).

chaocharleswang avatar May 27 '19 16:05 chaocharleswang

Hm. That's weird. But I'll take a look and try to reproduce the problem. Thanks for the report!

Mauker1 avatar May 27 '19 18:05 Mauker1

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);
        });

chaocharleswang avatar May 27 '19 18:05 chaocharleswang

Can I manage history by myself, e.g., add history, save and load history?

chaocharleswang avatar Sep 30 '19 22:09 chaocharleswang