Home > Blockchain >  Deleting a number in EditText with button click
Deleting a number in EditText with button click

Time:09-30

I am making a calculator with a delete button. I want the delete button to delete one element at a time.

Example, when I press DEL btn, the no.3 will be removed from the EditText.

enter image description here

This is my code for the dlt btn

        if (txtResult.length() > 0){
            txtResult = txtResult.getText().Remove(txtResult.length() - 1);
            if (txtResult.equals("")){
                txtResult.setText("0");
            }
        }
    }

What is the equivalent of .Remove from c# to android studio java? Thank you.

CodePudding user response:

You can delete the string with substring.
Try this:

String a = "AAA";
a = a.substring(0, a.length() - 1);
System.out.println(a); // result: AA
  • Related