とスーパータイプからメソッドをオーバーライドまたは実装していません。 は私がなぜ...方法は、私はこのエラーを持っているonTouch
を理解していないこれは私のTouchListenerImpl.java
です:
class TouchListenerImpl implements View.OnTouchListener {
private boolean movingDownL, movingDownR, movingLeft, movingRight, movingSuccessL, movingSuccessR = false;
private Point oldCoordsL, oldCoordsR, startPointL, startPointR = new Point(0, 0);
private boolean admin_touch = false;
private OnLTouch callback;
void setCallback(OnLTouch c) {
callback = c;
}
interface OnLTouch {
void lTouchSuccess();
}
@Override
public boolean onTouch(View v, MotionEvent event) {
Log.d("debugTouch", "onTouch");
int pIndexL = event.findPointerIndex(event.getPointerId(0));
int pIndexR = 0;
if(event.getPointerCount() > 1) pIndexR = event.findPointerIndex(event.getPointerId(1));
if(event.getPointerCount() > 1 && event.getX(pIndexL) > event.getX(pIndexR)) {
int tmp = pIndexR;
pIndexR = pIndexL;
pIndexL = tmp;
}
switch (event.getAction()) {
case MotionEvent.ACTION_DOWN:
movingDownL = true;
movingDownR = true;
movingSuccessL = false;
movingSuccessR = false;
if(event.getPointerCount() > 1) {
startPointR = new Point((int) event.getX(pIndexR), (int) event.getY(pIndexR));
oldCoordsR = new Point((int) event.getX(pIndexR), (int) event.getY(pIndexR));
}
startPointL = new Point((int) event.getX(pIndexL), (int) event.getY(pIndexL));
oldCoordsL = new Point((int) event.getX(pIndexL), (int) event.getY(pIndexL));
break;
case MotionEvent.ACTION_MOVE:
int downMinDistance = 300;
int lnrInaccuracy = 10;
int downInaccuracy = 30;
if(event.getPointerCount() > 1) {
if(!movingDownR) {
if(Math.abs(oldCoordsR.x - event.getX(pIndexR)) < downInaccuracy &&
oldCoordsR.y < event.getY(pIndexR)) break;
if(Math.abs(oldCoordsR.y - event.getY(pIndexR)) < lnrInaccuracy &&
oldCoordsR.x > event.getX(pIndexR) && !movingRight) {
movingRight = true;
startPointR = new Point(new Point((int)event.getX(pIndexR), (int)event.getY(pIndexR)));
}
} else {
if (Math.abs(oldCoordsR.x - event.getX(pIndexR)) > downInaccuracy ||
oldCoordsR.y < event.getY(pIndexR)) {
movingDownR = false;
break;
} else if(findDistance(startPointR,
new Point((int)event.getX(pIndexR), (int)event.getY(pIndexR))) >= downMinDistance){
movingDownR = false;
}
}
}
if(!movingDownL) {
if(Math.abs(oldCoordsL.x - event.getX(pIndexL)) < downInaccuracy &&
oldCoordsL.y < event.getY(pIndexL)) break;
if(Math.abs(oldCoordsL.y - event.getY(pIndexL)) < lnrInaccuracy &&
oldCoordsL.x < event.getX(pIndexL) && !movingLeft) {
movingLeft = true;
startPointL = new Point(new Point((int)event.getX(pIndexL), (int)event.getY(pIndexL)));
}
}else {
if (Math.abs(oldCoordsL.x - event.getX(pIndexL)) > downInaccuracy ||
oldCoordsL.y > event.getY(pIndexL)) {
movingDownL = false;
break;
} else if(findDistance(startPointL,
new Point((int)event.getX(pIndexL), (int)event.getY(pIndexL))) >= downMinDistance){
movingDownL = false;
}
}
int lnrMinDistance = 50;
if(movingLeft) {
if (Math.abs(oldCoordsL.y - event.getY(pIndexL)) > lnrInaccuracy ||
oldCoordsL.x > event.getX(pIndexL)) {
movingLeft = false;
break;
} else if(findDistance(startPointL,
new Point((int)event.getX(pIndexL), (int)event.getY(pIndexL))) >= lnrMinDistance) {
movingLeft = false;
movingSuccessL = true;
}
}
if(movingRight) {
if (Math.abs(oldCoordsR.y - event.getY(pIndexR)) > lnrInaccuracy ||
oldCoordsR.x < event.getX(pIndexR)) {
movingRight = false;
break;
} else if(findDistance(startPointR,
new Point((int)event.getX(pIndexR), (int)event.getY(pIndexR))) >= lnrMinDistance) {
movingRight = false;
movingSuccessR = true;
}
}
if(movingSuccessL && movingSuccessR) {
if (!admin_touch)
{
admin_touch = true;
if (callback != null)
callback.lTouchSuccess();
}
}
oldCoordsL = new Point((int)event.getX(pIndexL), (int)event.getY(pIndexL));
oldCoordsR = new Point((int)event.getX(pIndexR), (int)event.getY(pIndexR));
break;
case MotionEvent.ACTION_UP:
movingDownL = false;
movingDownR = false;
movingLeft = false;
movingRight = false;
break;
default:
return false;
}
return true;
}
private double findDistance(Point p1, Point p2) {
return Math.sqrt(Math.pow(p1.x - p2.x, 2) + Math.pow(p1.y - p2.y, 2));
}
}
私はTouchListenerImpl
(TESTActivity.java
)を呼び出す場所です:
public class TESTActivity extends AppCompatActivity {
TouchListenerImpl imp = new TouchListenerImpl();
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_test);
imp.setCallback(new TouchListenerImpl.OnLTouch() {
@Override
public void lTouchSuccess() {
Log.d("debug", "success");
}
});
}
@Override
public boolean onTouch(View v, MotionEvent event) {
return imp.onTouch(v, event);
}
}
あなたのアクティビティのスーパータイプはこのようなメソッドを持たず、オーバーライドできない – Selvin