Java tutorial
//package com.java2s; import android.text.Editable; import android.text.Selection; import android.widget.EditText; public class Main { public static void insert(EditText input, CharSequence text) { int iCursorStart = Selection.getSelectionStart((input.getText())); int iCursorEnd = Selection.getSelectionEnd((input.getText())); if (iCursorStart != iCursorEnd) { ((Editable) input.getText()).replace(iCursorStart, iCursorEnd, ""); } int iCursor = Selection.getSelectionEnd((input.getText())); ((Editable) input.getText()).insert(iCursor, text); } }