Clearing the single character before cursor position in EditText
android, button, cursor-position
Solution
I think its late but still.
You can use SpannableStringBuilder.
//getting cursor position
int end = t1.getSelectionEnd();
//getting the selected Text
SpannableStringBuilder selectedStr=new SpannableStringBuilder(t1.getText());
//replacing the selected text with empty String and setting it to EditText
selectedStr.replace(end-1, end, "");
edittext1.setText(selectedStr);
Problem
With the below code i am replacing the all characters(if my edittext contains four a's all a's are removed here) that contains substring and the cursor position is goes to before first character in edittext field. ``` //getting cursor position int end = t1.getSelectionEnd(); //getting the selected Text String selectedStr = t1.getText().toString().substring(end-1, end); //replacing the selected text with empty String and setting it to EditText t1.setText(t1.getText().toString().replace(selectedStr, "")); ``` How can i clear the single character before the cursor position(if my cursor is middle of the edittext) without changing the cursor position.