SearchView widget - any way to SELECT ALL text inside?
I'm using SearchView widget (new in Honeycomb). I can set initial text by setQuery, that works.
But is there some way to select all text inside (similar to EditText.selectAll)?
I'd like to give user preset text from previous searc开发者_JAVA技巧h, yet easy way to type new text without need to delete old.
You just need to capture the inner EditText, then do anything you want.
EditText edit = (EditText)searchView.findViewById(R.id.search_src_text);
edit.selectAll();
A little late but i had a similar issue.
I'd like to give user preset text from previous search, yet easy way to type new text without need to delete old.
I found a solution that worked for me. You just need to access to the inner EditText and then select all the text in usual way.
To do this try something like the following. Please note that my code is in c# not in Java but its similar.
int id = searchView.Context.Resources.GetIdentifier("android:id/search_src_text", null, null);
EditText editText = searchView.FindViewById<EditText>(id);
editText.SelectAll();
In Java it should be something like this:
int id = searchView.getContext().getResources().getIdentifier("android:id/search_src_text", null, null);
EditText editText = (EditText) searchView.findViewById(id);
editText.selectAll();
I have just testet it on API level 15! But i think it works on lower levels, too.
What you want to do works well on PCs, but but is not very convenient on touch devices.
I'd use suggestion provider to allow user to reuse recent searches, possibly with query refinement enabled.
精彩评论