我是新的android开发人员。我想问个问题。这是我需要的:用户单击“后退”按钮时,是否算作双击?@Override public void onBackPressed() { --> what to write here? return; }}
最佳答案
您需要检查两次按压之间的间隔,并确定是否可以将其计为双击:
private static final long DOUBLE_PRESS_INTERVAL = /* some value in ns. */;
private long lastPressTime;
@Override
public void onBackPressed() {
long pressTime = System.nanoTime();
if(pressTime - lastPressTime <= DOUBLE_PRESS_INTERVAL) {
// this is a double click event
}
lastPressTime = pressTime;
}