Making backspace button in java that deletes the last character in a Textview


I want to make a button that acts like a backspace but I cant find the perfect code for doing it, like I made a button that adds certain characters to a Textview using append() method in a single line of code instead of making a multiple line thingy.
So my question is: is there a way to do it in a backspace button code, I know I can make a multiple line/long code, but is there an opposite to append()?


This works for character backspace:

buttonBackspace.setOnClickListener(new View.OnClickListener() {

        public void onClick(View view) {
           String word = editText.getText().toString();               
           int input = word.length();
              if (input > 0){
                 editText.setText(word.substring(0, input-1));

Answered By – princessdharmy

This Answer collected from stackoverflow, is licensed under cc by-sa 2.5 , cc by-sa 3.0 and cc by-sa 4.0

Leave a Reply

(*) Required, Your email will not be published