Skip to content
This repository has been archived by the owner on Feb 25, 2025. It is now read-only.

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 subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
None yet
Projects
None yet
Development

No branches or pull requests

3 participants