Search code examples
androidsearchable

Variable search hint


In my searchable.xml in my android project, I get to specify a hint that appears in the edittext, when no text is written. Is there any way to dynamically set this?

In my action, I have two search buttons, that are calling startSearch passing their own parameters. I would like to set hints that reflect the selected action, based on which button was clicked - say "search movie titles", "search actors".

The way I see it, this could potentially be achievable by passing parameters to startSearch, or using a localization approach, just as I could place one hint in values-fr\strings.xml, there might be an alternative search resource file to target for when another button has been clicked? Or if the searchable.xml could be made into a selector, so that I could have it act differently in different states, somehow, that would also be fine... Problem is I haven't been able to find a means of achieving any of these.

The real reason I want to be doing this, is because the way I see it, it's the best way of communicating that the default action, when the device search button is pressed, is the first option, title search.

UPDATE

To avoid confusion, I'm happy with any declarative or programmatic approach of changing the hint in the EditText mSearchTextField in SearchDialog. What I'm unclear about is how to reference that EditText. The comments in the code linked to says "This is still controlled by the SearchManager ..." but I can't find any reference to how it can be controlled from the SearchManager either.


Solution

  • AFAIK, There isn't any way you can access the EditText provided for search.