Android edittext

I have one editor EditText et1 = (EditText) findViewById (R.id.EditText01);

when I want to clear edittext, I use et1.setText (""); but if I have to clear the edittext one character from the last for that I have no solution that can give me a solution

+3
source share
3 answers

Do you know about SubString?

String contents = et1.getText().toString();
et1.setText(contents.substring(0, contents.length()-2));
+4
source

Well, if you know you want to clear, you can get the text from edittext, and then remove the number of characters from the end using string.substring (0, numOfEND);

+1
source

editText , :

if (et1.getSelectionStart() > 0) { //check that you are not deleting from the zero point
    et1.getText().delete(et1.getSelectionStart()-1, et1.getSelectionEnd());
}
+1

Source: https://habr.com/ru/post/1764841/


All Articles