开发者

Android long key press

I need to generate/trigger a 开发者_C百科long key press event of a button in Android.

Any help regrading this?


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.


You can set Long key press on button like:

btnNext.setLongClickable(true);
btnNext.setOnLongClickListener(l)
0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜