android keylistener losing key taps
I am 开发者_StackOverflowusing 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,
精彩评论