1

I am trying to override the delete button of my soft keyboard. I am able to detect the delete button being pressed but only if the EditText is empty. Is there a way of detecting if it has been pressed when there is text in my EditText? What i want to do is override the delete button to make it delete the entire contents of the EditText instead of just letter by letter. Below is the code I am using:

mEtCoupon.setOnKeyListener(new View.OnKeyListener() {
            @Override
            public boolean onKey(View v, int keyCode, KeyEvent event) {
                // You can identify which key pressed buy checking keyCode value
                // with KeyEvent.KEYCODE_
                if (keyCode == KeyEvent.KEYCODE_DEL) {
                    // this is for backspace

                    Log.e("IME_TEST", "DEL KEY");
                }
                return false;
            }
        });

Is it possible to do this?

Algorithmist
  • 6,657
  • 7
  • 35
  • 49
DMC
  • 1,184
  • 5
  • 21
  • 50
  • 1
    I don't know whether it's possible, but I would, very, _very_ strongly recommend against it. Don't change the normal behaviour of the user's keyboard. Especially in a way like this. If your user is expecting one character to disappear, don't delete everything. – Michelle Aug 13 '13 at 15:43
  • This answer might help you: http://stackoverflow.com/a/11377462/2291915 – buczek Aug 13 '13 at 15:51

0 Answers0