当我按下按钮然后将其移到按钮的边界外时,onTouchListener
继续射击。
当我按下按钮上的一根手指和按钮外的第二根手指时,同样的事情发生了:我的onTouchListener
为第二根手指开火。
我该如何避免这种情况?我只想在按下按钮的界限时才开火onTouchListener
。
这是我的onTouchListener
实施
View.OnTouchListener onTouchListener = new View.OnTouchListener() {
@Override
public boolean onTouch(View v, MotionEvent event) {
if (fingerDown) {
xHistoricalFirstFinger = (int) event.getX();
yHistoricalFirstFinger = (int) event.getY();
xFirstClick = xHistoricalFirstFinger;
yFirstClick = yHistoricalFirstFinger;
//counter++;
fingerDown = false;
}
x = (int) event.getX();
y = (int) event.getY();
Log.v("Touched", client.remoteAdress.toString());
mouseMoveProvider.nextX = x - xHistoricalFirstFinger;
mouseMoveProvider.nextY = y - yHistoricalFirstFinger;
mouseMoveProvider.Ready = true;
xHistoricalFirstFinger = x;
yHistoricalFirstFinger = y;
if (event.getAction() == MotionEvent.ACTION_UP) {
if (x - xFirstClick == 0 & y - yFirstClick == 0) {
new Thread(new Runnable() {
@Override
public void run() {
try {
client.MakeMove();
} catch (IOException e) {
e.printStackTrace();
NetworkListener.HandleNetworkIsUreachableException(context);
}
}
}).start();
}
fingerDown = true;
}
return true;
}
};
答案 0 :(得分:1)
答案 1 :(得分:0)
使用onClickListener
?
onTouchListener
将触发每次触摸(手指向下,手指向上......)