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?
Asked
Active
Viewed 7,052 times
2 Answers
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.
-
7To 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
-
1This 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