I am overriding the backbutton with a onBackPressed() function
how开发者_JAVA技巧 do I also detect long clicks on the backbutton? Is there an equivalent of @Override onBackLongPressed() ?
This might help you (Check the first comment) - Android long key press
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);
}
Check "Story 2" here. There's not a shortcut for it like there is onBackPressed().
I think you'll have to use onKeyLongPress and handle the KEYCODE_BACK event yourself.
精彩评论