tags:

views:

447

answers:

2

requestFocus() moves cursor to edit box, but does not highlight it. I want to highlight it like as if it was touched.

+1  A: 

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();
jeremynealbrown
Sorry, seems I was not explicit enought... I am talking about highlighting around the edit area, not the text selection.
alex2k8
+3  A: 

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();
alex2k8