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

How to persistence search text #19

Open
webserveis opened this issue Aug 24, 2019 · 3 comments
Open

How to persistence search text #19

webserveis opened this issue Aug 24, 2019 · 3 comments

Comments

@webserveis
Copy link

webserveis commented Aug 24, 2019

with .setKeepQuery(true) add persistence last query, but is there any way to initialize the text to a specific value?

@webserveis
Copy link
Author

Hey, I found this

        searchView.setQuery("set default text", false)

false: no submit result
true: propagate submit result

@67Samuel
Copy link

This does not set the text for me, I do the following but it just gives me an empty search view:

    if (queryText.isNotEmpty()) {
            searchView.showSearch()
            searchView.setQuery(queryText, false)
        }

@goemic
Copy link

goemic commented Sep 27, 2024

It's important to wait until layout is ready:

mBinding.searchView.doOnLayout { _ ->
       // wait for layout to be finished, otherwise showSearch() will not work
       mBinding.searchView.showSearch()
       // text needs to be set after showSearch() is called!
      mBinding.searchView.setQuery(voucherSearchString, false)
}

If you want to enable searchView.setKeepQuery(true) you can also set the query value before opening the searchView:

mBinding.searchView.doOnLayout { _ ->
      mBinding.searchView.setKeepQuery(true)
      mBinding.searchView.setQuery(voucherSearchString, false)
      mBinding.searchView.showSearch()
}

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

No branches or pull requests

3 participants