When deleting a character, how do I execute something?

Asked

Viewed 81 times

0

I am using this method to delete the last character typed in a TextView:

texto = txtTexto.getText().toString();
int length = texto.length();  
txtTexto.setText(texto.substring(0, length - 1));

But when deleting a character, like a dot ".", I want you to do something.

1 answer

5


It’s not very clear what you want to do, but if you want to check if the last character is a dot, do it:

int length = texto.length();

if (texto.substring(length - 1, length).equals(".")) {
    funcao_qualquer();
}

texto = txtTexto.getText().toString();
txtTexto.setText(texto.substring(0, length - 1));
  • "But when deleting a character, like a dot "." I want it to perform something." It wants to call a function by deleting the last character from the textview.

Browser other questions tagged

You are not signed in. Login or sign up in order to post.