Manuel Manuel - 1 month ago 13
Android Question

Android: Insert text into EditText at current position

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.

Answer

Try using EditText.getSelectionStart() to get the current position of the cursor. Then you can use String.subString to get the text before and after the cursor and insert your text in the middle.

Haven't tried though.

Comments