[英]public class MainActivity extends AppCompatActivity implements GestureDetector.OnGestureListener
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);
}
this line:这一行:
public class MainActivity extends AppCompatActivity implements GestureDetector.OnGestureListener
is red and reads this error:为红色并读取此错误:
Error:(12, 8) error: MainActivity is not abstract and does not override abstract method onLongPress(MotionEvent) in OnGestureListener错误:(12, 8) 错误:MainActivity 不是抽象的,并且不会覆盖 OnGestureListener 中的抽象方法 onLongPress(MotionEvent)
First of all import the necessary headers.首先导入必要的头文件。 [press the combination cmd + shift + O if it is windows] [如果是windows,按组合cmd + shift + O]
After that you will see a error under MainActivity.之后,您将在 MainActivity 下看到错误。 Move the cursor on to MainActivity and click on implement methods.将光标移动到 MainActivity 并单击实现方法。
Since you have declared the MainActivity
class as implementing the OnGestureListener
interface, you have to implement all of the methods that that interface defines.由于您已将MainActivity
类声明为实现OnGestureListener
接口,因此您必须实现该接口定义的所有方法。
You haven't done that.你没有那样做。
Solution: do that.解决办法:这样做。
Here's an example that may help you:这是一个可能对您有所帮助的示例:
https://github.com/filajust/man-from-mars/blob/master/ManFromMars/src/edu/msu/filajustmanfrommars/GameView.java https://github.com/filajust/man-from-mars/blob/master/ManFromMars/src/edu/msu/filajustmanfrommars/GameView.java
Note that the example uses GestureDetector.SimpleOnGestureListener
to implement the listener functionality.请注意,该示例使用GestureDetector.SimpleOnGestureListener
来实现侦听器功能。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.