Cancel onKey Event from onKey method

Posted by user244190 on Stack Overflow See other posts from Stack Overflow or by user244190
Published on 2010-05-20T17:53:10Z Indexed on 2010/05/20 18:10 UTC
Read the original article Hit count: 158

Filed under:
|

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;
        }

© Stack Overflow or respective owner

Related posts about android

Related posts about listeners