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 search, 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.
Related
I am wondering why Android doesn't support this.
To explain my problem. I am working on an accessibility feature for an Android app.
I have a TextView that displays a number value like 123456.
If I use TalkBack, it will always read just this number value.
What I want it to give this value a context so that TalkBack would read something like: "Number value 123456" I am not able to do that as contentDescription just overrides the text value and hint attribute is read after the value like: "123456 Number value".
Is there an alternative for this? Let me also say that the app is not using a separate TextView which would say "Number value" that TalkBack could read.
The solution I did was to use
var number = 123456
textView.contentDescription = "Number value ${number}"
I have an Android EditText with suggestions enabled. My goal is not to disable suggestion (since i'm able to do that), but to skip some string values from them.
For example, suppose that i'd like to skip 'hello' word.
If i write 'he' in the EditText, my suggestions list shouldn't contain 'hello' since it's a string that has to be skipped. Is it possible?
Hope i explained myself, thanks
I'm working on a application project as my bachelor thesis and I wonder if it's possible to set a text in a Edittext box?
I'm not talking about the editText.setHint("My text"), or android:hint in the XML. I want to fetch a variable from a Web Service (This variable may change depend on what you do ).
For example. You have a shoppinglist. The list says "Go buy two pieces of bread ", and the editText Box is supposed to have " 2 " in the box (so you can directly proceed from there) but if you didn't buy two pieces of bread, you can edit it to " 1 ".
It's hard to explain this, but I hope you guys understands. If not, let me know and I'll try to explain again.
Thanks in advanced!
Just use
EditText editText = (EditText)findViewById(R.id.edit_text_id);
editText.setText("1");
simple:
EditText editText = (EditText)findViewById(R.id.your_edit_text_id);
editText.setText("1", TextView.BufferType.EDITABLE);
I am creating an android application. The first thing I'm creating is a login activity. I am trying to limit the username edittext just to text/numbers only (no special characters). Is there a way to adjust this in the xml file?
I dont think you can limit the characters from xml. You could always use a InputFilter, but specifically android provides UsernameFilterGeneric to filter valid user names. You could also use UsernameFilterGMail
As you already use in java Regular expression.called the same class here for checking for particular field.
let me know if you want some more if you didn't know about the RE.
I've searched high and low for something that seems to be a simple task. Forgive me, I am coming to Android from other programming languages and am new to this platform and Java.
What I want to do is create a dialog pop-up where a user enters text to search for and the code would take that text and search for it within all the text in an EditText control and if it's found, highlight it.
I've done this before, for example in VB and it went something similar to this pseudo code:
grab the text from the (EditText) assign it to a string
search the length of that string (character by character) for the substring, if it's found return the position (index) of the substring within the string.
if found, start the (EditText).setSelection highlight beginning on the returned position for the length of
Does this make sense?
I just want to search a EditText for and when found, scroll to it and it'll be highlighted. Maybe there's something in Android/Java equivalent to what I need here?
Any help / pointers would be greatly appreciated
grab the text from the (EditText) assign it to a string
Try the code sample below:
EditText inputUsername = (EditText) findViewById(R.id.manageAccountInputUsername);
inputUsername.getText().toString()
^^ Replace the IDs with the IDs you are using.
After this, you have the standard string methods available. You could also use Regex for a complex search query:
http://developer.android.com/reference/java/lang/String.html
http://developer.android.com/reference/java/util/regex/package-summary.html