views:

29

answers:

1

Is it possible to cancel an event from within the onKey method. I only want to allow numbers 0 through 9. If another key was pressed then I want to cancel the key press

public boolean onKey(View v, int keyCode, KeyEvent ev) {
            // TODO Auto-generated method stub

            if(keyCode <30 || keyCode > 39){
               //Cancel Event
            }
            return false;
        }
+1  A: 

Is this to restrict input into a text field? An easier way to do that is to set the inputType to number, which will cause the number keyboard to appear, and digits to true. I believe this second will restrict input from a physical keyboard..

Mayra
Already had numeric set to Integer, but not digits, which actually is a set of valid keys. In my case I set up a resource array of 0 through 9. Works Great! Thanks Mayra