Android: Insert text into EditText at current position

Viewed 44097

I want to insert a constant string into an EditText by the press of a button. The string should be inserted at the current position in the EditText. If I use EditText.append the text gets inserted at the end of the EditText.

How can I do that? I couldn't find a suitable method.

6 Answers

For Kotlin simply do that:

editText.text.insert(editText.selectionStart, "Your Text Here")

Editable editable = new SpannableStringBuilder("Pass a string here");

yourEditText.text = editable;

Related