onTouchEvent不能@Override

时间:2012-03-17 04:02:05

标签: java android service

您好我想使用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不起作用的原因。

2 个答案:

答案 0 :(得分:1)

OnGestureListener中没有onTouchEvent会导致您的错误(没有可覆盖的内容)。你究竟想对这件事做什么?您可以使用onDown和onSingleTapUp来模拟事件。 但是,您可以从View收听onTouch(),但我没有看到任何与您发布的视图相关的代码。

答案 1 :(得分:0)

试试这个

@Override
public boolean onTouchEvent(MotionEvent me) {
    if (gestureScanner.onTouchEvent(me))
        return true;
    else
        return false;
}

我希望这会奏效。