문제

I use the following code to listen for the key presses of 0 - 9 from the soft input keyboard on Android:


@Override
        public boolean onKeyDown(int keyCode, KeyEvent event)  {

            if(keyCode == KeyEvent.KEYCODE_0)
            {
                return super.onKeyDown(keyCode, event);
            }

            if(keyCode == KeyEvent.KEYCODE_1)
            {
                return super.onKeyDown(keyCode, event);
            }

            if(keyCode == KeyEvent.KEYCODE_2)
            {
                return super.onKeyDown(keyCode, event);
            }

            if(keyCode == KeyEvent.KEYCODE_3)
            {
                return super.onKeyDown(keyCode, event);
            }

            if(keyCode == KeyEvent.KEYCODE_4)
            {
                return super.onKeyDown(keyCode, event);
            }

            if(keyCode == KeyEvent.KEYCODE_5)
            {
                return super.onKeyDown(keyCode, event);
            }

            if(keyCode == KeyEvent.KEYCODE_6)
            {
                return super.onKeyDown(keyCode, event);
            }

            if(keyCode == KeyEvent.KEYCODE_7)
            {
                return super.onKeyDown(keyCode, event);
            }

            if(keyCode == KeyEvent.KEYCODE_8)
            {
                return super.onKeyDown(keyCode, event);
            }

            if(keyCode == KeyEvent.KEYCODE_9)
            {
                Log.d("Keycode", "Got KeyCode 9");
                return super.onKeyDown(keyCode, event);
            }

            return true;
        }

The code works when i display the soft input keyboard in the following mode:

alt text

However it does not work when I display the soft input keyboard in the following mode:

alt text

Why is this?

도움이 되었습니까?

해결책

It is because there are different keycodes for the number pad. Unfortunately they were only introduced in API Level 11 (android 3.0, honeycomb) so you will have to find another way to address those guys for maximum compatibility.

라이센스 : CC-BY-SA ~와 함께 속성
제휴하지 않습니다 StackOverflow
scroll top