How to set focus to right of text in EditText for android?

Viewed 24624

In my application when users click or touch on the Edit Text view the focus is sometimes set to the beginning. For example if the existing text is "Hi". Users wants to click on it and change it to "H1 How are you?" by adding the text "How are you?". But since the focus is in the beginning, it becomes "How are you?Hi". So I always want to set to focus to the right most of the text when selected. How do I do this. Please let me know with some sample if possible. Thank you for your time and help.

8 Answers

Inside the addTextChangedListener():

@Override
public void afterTextChanged(Editable editable) {
    viewHolder.editText.setSelection(viewHolder.editText.getText().length());       //set cursor to the end
}
Related