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)
精彩评论