Manuel Manuel - 1 year ago 170
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

the text gets inserted at the end of the EditText.

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

Answer Source

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.

Recommended from our users: Dynamic Network Monitoring from WhatsUp Gold from IPSwitch. Free Download