AndroidでonTouchとonClick紛争問題の解決
public boolean onTouchEvent(MotionEvent event) {
final int action = event.getAction();
final int moveX = (int)event.getX();
final int scape = moveX – firstX;
switch (action) {
case MotionEvent.ACTION_DOWN:
firstX = (int) event.getX();//押したらxの位置を開始
break;
case MotionEvent.ACTION_MOVE:
if (isMove) {
move(scape);
}
break;
case MotionEvent.ACTION_CANCEL:
case MotionEvent.ACTION_UP:
secondX = (int)event.getX();//upしたらxの位置
int distance = secondX – firstX;
if (distance == 0) {
//変化がない場合何もしない
}else {
//moveを実行して移動後の動作
}
break;
}
return true;
}