I want to clear the entire text on EditText which is before the cursor position. Suppose i the text is 1234567890, the cursor is after the character 4 like this 1234|567890 Now my requirement is I have a custom button, which deletes the text before cursor position.
I am using editext.getText().clear();
to clear the text, but its clearing entire text. If the cursor is at end of text, it is good.
Is it possible to achieve my requirement ? If yes how ? Please help me regarding this.
Here is how to deal with it:
You will get Cursor Position using:
or
Note: if no text is selected, both methods will return the same index.
Then sub-string the text
EditText
and then set again toEditText
. something like this:Following answer may help you .Its working perfect for me
To insert the text/char at selected position of
EditText
cursorTo delete the text/char at selected position of
EditText
cursorTo set
EditText
cursor at last positionThis is XML code for
EditText