Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Android long key press

Tags:

android

I need to generate/trigger a long key press event of a button in Android.

Any help regrading this?

like image 643
viv Avatar asked Aug 04 '10 07:08

viv


1 Answers

From Android 2.0, Activity contains the method

public boolean onKeyLongPress(int keyCode, KeyEvent event)

For exemple, a long key press on the back button would be :

@Override
public boolean onKeyLongPress(int keyCode, KeyEvent event) {
    if (keyCode == KeyEvent.KEYCODE_BACK) 
    {
        // do your stuff here
        return true;
    }
    return super.onKeyLongPress(keyCode, event);
}

Take a look at this article.

like image 74
rockeye Avatar answered Oct 28 '22 15:10

rockeye