Long key press handling in android 1.5

Posted by Kaillash on Stack Overflow See other posts from Stack Overflow or by Kaillash
Published on 2010-04-21T05:21:51Z Indexed on 2010/04/21 5:23 UTC
Read the original article Hit count: 180

Filed under:
|

Hi,

I want to handle key press and long key press for the key code KEYCODE_BACK(back button). can any one suggest me how to do this in android 1.5(API level 3).

Here is the code.

public boolean onKeyDown(int keyCode, KeyEvent event) {
        if (keyCode == KeyEvent.KEYCODE_BACK) {

                if(event.getRepeatCount()==0) {
                   // normal key press
                   // But problem is, this code is hitting for long press also, how to avoid this
                } else {
                    // Long key press
                    //Do something here
                }
                // Always consume back key event by returning true
                //so that default behavior of back is overrided
                return true;
            }
        return super.onKeyDown(keyCode, event);
    }

© Stack Overflow or respective owner

Related posts about android

Related posts about keyevent