3

When onKeyListener is set Backspace/delete key is not functioning.

I set an OnKeyListener on my EditText. Then default actions of some keys became not functioning. Like DELETE/Backspace. Then I changed to use my own text-deleting function by manipulating the string inside. But it seems to be pretty complex.

I have to get selection, make substring, and so on. Are there other solutions to get the key functioning normally?

r4.
  • 358
  • 1
  • 6
  • 22
M Rijalul Kahfi
  • 1,460
  • 3
  • 22
  • 42

4 Answers4

3

It depends on the IME you are using. Some IME implements delete function without sending KEYCODE_DEL. Try other IME than the default.

For example, if you press DEL button long enough, some IME deletes all text in the edit box. This cannot be done through KEYCODE_DEL.

JonA
  • 605
  • 6
  • 6
2

I had this problem too, I solved it by returning false in onKeyListener function. This should execute normal operations on other keys.

.setOnKeyListener(new DialogInterface.OnKeyListener() 
{
     @Override public boolean onKey(DialogInterface dialog, int keyCode, KeyEvent event) 
     {
        //your workarounds;
        return false;
     }
})
0

There are two known issues affecting KEYCODE_DEL for the default (LatinIME) Google Keyboard that ships with Android: Issues 42904 and 62306.

I have researched this and have devised a workaround, with code, that seems to get around both of these issues. That workaround can be found here:

Android - cannot capture backspace/delete press in soft. keyboard

Community
  • 1
  • 1
Carl
  • 15,445
  • 5
  • 55
  • 53
0

I have similar problems that you are facing and I somehow managed to stumble on the solution. Apparently, I had setOnKeyListener to 'return true'. After I changed it to 'return false', the phone keyboard works perfect with backspace functioning properly once again on edittext. Hope this helps:

Solution: One of your existing onkeylistener codes contain 'return true'. Rectify it by setting existing code from 'return true' to 'return false'

.setOnKeyListener(new View.OnKeyListener() {
            public boolean onKey(View v, int keyCode, KeyEvent event) {
  ...
  return false;
                }
        });
Kevin
  • 109
  • 6