Try using the following code
int start =editText.getSelectionStart(); //this is to get the the cursor position String s = "Some string"; editText.getText().insert(start, s); //this will get the text and insert the String s into the current position
Here is the code to remove selected text from EditText
int start = t1.getSelectionStart(); //getting cursor starting position int end = t1.getSelectionEnd(); //getting cursor ending position String selectedStr = t1.getText().toString().substring(start, end); //getting the selected Text t1.setText(t1.getText().toString().replace(selectedStr, "")); //replacing the selected text with empty String and setting it to EditText
source share