[英]Android detect the long key press of a button
我使用遙控器訪問設備。
就我而言,當我按下按鍵按下和按鍵按下上的任何按鈕時,都會連續調用事件。
我認為onkey up事件僅應在釋放鍵期間調用,而應在按下按鈕時調用。
有什么方法可以解決這個問題,也可以采用其他解決方案跟蹤長按?
long lastDown;
long keyPressedDuration ;
button.setOnTouchListener(new OnTouchListener() {
@Override
public boolean onTouch(View v, MotionEvent event) {
if(event.getAction() == MotionEvent.ACTION_DOWN) {
lastDown = System.currentTimeMillis();
} else if (event.getAction() == MotionEvent.ACTION_UP) {
keyPressedDuration = System.currentTimeMillis() - lastDown;
}
}
};
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.