java公共类MainActivity扩展了AppCompatActivity,实现了GestureDetector。OnEstureListener
public class MainActivity extends AppCompatActivity implements GestureDetector.OnGestureListener {
private GestureDetectorCompat gestureDetector;
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main);
Log.i(TAG, "onCreate");
this.gestureDetector = new GestureDetectorCompat(this,this);
}
这一行:
public class MainActivity extends AppCompatActivity implements GestureDetector.OnGestureListener
为红色,显示以下错误:
Error:(12, 8) error: MainActivity is not abstract and does not override abstract method onLongPress(MotionEvent) in OnGestureListener
# 1 楼答案
由于您已将
MainActivity
类声明为实现OnGestureListener
接口,因此必须实现该接口定义的所有方法你还没那么做
解决方案:这样做
以下是一个可能对您有所帮助的示例:
https://github.com/filajust/man-from-mars/blob/master/ManFromMars/src/edu/msu/filajustmanfrommars/GameView.java
请注意,该示例使用
GestureDetector.SimpleOnGestureListener
来实现侦听器功能# 2 楼答案
首先,导入必要的标题。[如果是windows,则按组合键cmd+shift+O]
之后,您将在MainActivity下看到一个错误。将光标移到MainActivity并单击Implemental methods