Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

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

Open
chaocharleswang opened this issue May 27, 2019 · 5 comments
Open

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

chaocharleswang opened this issue May 27, 2019 · 5 comments

Comments

@chaocharleswang
Copy link

chaocharleswang commented May 27, 2019

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

@Mauker1
Copy link
Owner

Mauker1 commented May 27, 2019

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.

@chaocharleswang
Copy link
Author

chaocharleswang commented May 27, 2019

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

@Mauker1
Copy link
Owner

Mauker1 commented May 27, 2019

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

@chaocharleswang
Copy link
Author

chaocharleswang commented May 27, 2019

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
Copy link
Author

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

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

2 participants