Variable search hint

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

In my action, I have two search buttons that call startSearch , passing their own parameters. I would like to set prompts that reflect the selected action, on the basis of which the button was clicked - say, “search for movie titles”, “search participants”.

As I see this, this could potentially be achieved by passing parameters to startSearch or using a localization approach, just as I could put one hint on values-fr\strings.xml , there could be an alternative search resource file for the target when another button pressed? Or, if searchable.xml could be made into a selector so that I could act differently in different states, anyway, that would be good too ... The problem is that I could not find a way to achieve any of them.

The real reason I want to do this is because, as I see it, the best way to tell you that the default action when the device’s search button is pressed is the first search option by name.

UPDATE

To avoid confusion, I am pleased with any declarative or programmatic approach to changing mSearchTextField in EditText mSearchTextField to SearchDialog . I do not understand how to reference this EditText. Comments in code related to: "This is still controlled by SearchManager ...", but I cannot find any link to how this can be controlled from SearchManager.

+4
source share
4 answers

AFAIK. You cannot access the EditText provided for the search.

+1
source

Android XML is not very dynamic; you may have to fix this problem in the action code.

You can do this in code by changing the tooltip in EditText using setHint() . Then you just need some kind of button listener (or maybe Spinner). For a button, you simply use setOnClickListener() ; for spinner setOnItemSelectedListener() would be more appropriate.

+1
source

I'm not sure what your startSearch looks like, but something like this is what you are looking for:

 private void startSearch(CharSequence hint) { EditText searchBox = (EditText)findViewById(R.id.my_edit_text); searchBox.setHint(hint); 
0
source

Can you add metadata to activity at runtime? If you could, then you can designate another xml file for search.

0
source

Source: https://habr.com/ru/post/1302202/


All Articles