requestFocus()
moves the cursor to the edit box, but does not highlight it. I want to highlight it like as if it was touched.
How can I do this?
Try this:
_field.setSelection( int startIndex, int endIndex);
The first parameter startIndex is the point in the string where you want to begin highlighting and the endIndex parameter is the point where you want to stop highlighting.
If you want to select all of the text use this instead:
_field.selectAll();
I found a bug. My code was some thing like this:
edit = new EditText();
edit.requestFocus()
container.addView(edit);
It moved cursor to new 'edit', but did not highlight it. This fixed it:
edit = new EditText();
container.addView(edit);
edit.requestFocus();
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With