3

I have comment box using EditText and it has several lines. When user returns to the box they are always at end of line 1 rather than end of say line 3 if there are three lines total in the box. How can I fix this?

barcodereader
  • 2,038
  • 4
  • 18
  • 20

2 Answers2

14

There might be easier ways perhaps, but one way is to use

editText.setSelection(editText.getText().length());

You can place this line inside an OnFocusChangeListener, or in a Create method.

Milo P
  • 1,377
  • 2
  • 31
  • 40
Aleadam
  • 40,203
  • 9
  • 86
  • 108
  • 7
    To place the cursor at the end of the text, it should be just `editText.setSelection(editText.getText().length());` – ismriv Mar 07 '12 at 12:48
  • 1
    This did not work for me. I have Spannable strings in my EditText. Is there a workaround for that? – Etienne Lawlor Dec 31 '12 at 10:19
0

You can also do this
final int selectionStart = editText.getSelectionStart(); final int selectionend = editText.getText().length();

Selection.setSelection(editText.getText(), selectionStart, selectionend);

Please make you are not calling setText after this because that will override the behavior.

maruti060385
  • 707
  • 8
  • 11