嗨,我想使用GestureDetector实现Service

但是我有此错误The method onTouchEvent(MotionEvent) of type GestureService must override or implement a supertype method

public class GestureService extends Service implements OnGestureListener {

private GestureDetector gestureScanner;

@Override
public IBinder onBind(Intent intent) {
    // TODO Auto-generated method stub
    return null;
}
@Override
public void onCreate() {
    super.onCreate();
    Toast.makeText(getBaseContext(),"onCreate", Toast.LENGTH_SHORT).show();
    gestureScanner = new GestureDetector(this);

}


@Override
public int onStartCommand(Intent intent, int flags, int startId) {
    Toast.makeText(getBaseContext(),"onStartCommand", Toast.LENGTH_SHORT).show();
    return START_STICKY;

 }

public boolean onTouchEvent(MotionEvent me) {

    return gestureScanner.onTouchEvent(me);
}

@Override
public boolean onDown(MotionEvent e) {
    // TODO Auto-generated method stub
    Toast.makeText(getBaseContext(),"onDown", Toast.LENGTH_SHORT).show();
    return false;
}
@Override
public boolean onFling(MotionEvent e1, MotionEvent e2, float velocityX,
        float velocityY) {
    // TODO Auto-generated method stub
    return false;
}
@Override
public void onLongPress(MotionEvent e) {
    // TODO Auto-generated method stub

}
@Override
public boolean onScroll(MotionEvent e1, MotionEvent e2, float distanceX,
        float distanceY) {
    // TODO Auto-generated method stub
    return false;
}
@Override
public void onShowPress(MotionEvent e) {
    // TODO Auto-generated method stub

}
@Override
public boolean onSingleTapUp(MotionEvent e) {
    Toast.makeText(getBaseContext(),"onSingleTapUp", Toast.LENGTH_SHORT).show();
    // TODO Auto-generated method stub
    return false;
}
 }


有什么办法可以解决它,而不是删除@Override,因为我怀疑删除它是导致GestureDetector无法正常工作的原因。

最佳答案

OnGestureListener中没有onTouchEvent会导致您出现错误(没有要覆盖的内容)。您想对该事件做什么?您可以使用onDown和onSingleTapUp模拟事件。
但是,您可以从View收听onTouch(),但至少从您发布的内容中,我看不到任何与View有关的代码。

关于java - onTouchEvent不能@Override,我们在Stack Overflow上找到一个类似的问题:https://stackoverflow.com/questions/9747135/

10-12 20:51