android keylistener losing key taps

Posted by miannelle on Stack Overflow See other posts from Stack Overflow or by miannelle
Published on 2011-01-09T01:48:58Z Indexed on 2011/01/09 1:53 UTC
Read the original article Hit count: 517

Filed under:
|

I am using a keylistener to get key taps. The problem is that once you tap the delete key, the next key tap is not registering. The key tap after that keeps working. If I tap 2 deletes in a row, they work, just no other keys. They just disappear.

I put in a log test before the "if (keycode" section and it shows nothing after the first delete is pressed, unless it is another delete.

I am using the following code (Thanks Shawn).:

itemPrice.setKeyListener(new CalculatorKeyListener());
itemPrice.setRawInputType(Configuration.KEYBOARD_12KEY);

class CalculatorKeyListener extends NumberKeyListener {
    public int getInputType() {
 return InputType.TYPE_CLASS_NUMBER;
    }

    @Override
    public boolean onKeyDown(View view, Editable content, int keyCode, KeyEvent event)
    {
 if (keyCode >= KeyEvent.KEYCODE_0 && keyCode <= KeyEvent.KEYCODE_9) {
     digitPressed(keyCode - KeyEvent.KEYCODE_0);
 } else if (keyCode == KeyEvent.KEYCODE_DEL) {                                         
     deletePressed();
 }
 return true;
    }

    @Override
    protected char[] getAcceptedChars() {
 return new char[] { 0, 1, 2, 3, 4, 5, 6, 7, 8, 9 };
    }
}

With this problem the keylistener provides no value to me. There must be something that I am missing.

Thanks,

© Stack Overflow or respective owner

Related posts about android

Related posts about keylistener