Android keylistener perdiendo pulsaciones de teclas

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.

Gracias,

preguntado el 09 de enero de 11 a las 01:01

Can you reproduce this behavior when you remove everything but your log from the onKeyDown()? Just to be sure that you didn't do anything wrong in the deletePressed() method... -

Yes I can. In fact, if there is NOTHING except a log in either place, the same still happens. Thanks. -

I apologize, there was an itemPrice.setText() in both. Without them, it captures all keystrokes. But the purpose of this is displaying/controlling the data input. -

0 Respuestas

No es la respuesta que estás buscando? Examinar otras preguntas etiquetadas or haz tu propia pregunta.