简体   繁体   English

公共类 MainActivity 扩展 AppCompatActivity 实现 GestureDetector.OnGestureListener

[英]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.

相关问题 GestureDetector.OnGestureListener与GestureDetector.SimpleOnGestureListener的作用是什么? - What is the purpose of GestureDetector.OnGestureListener versus GestureDetector.SimpleOnGestureListener? Android 开发 - GestureDetector.OnGestureListener 或 GestureDetector.SimpleOnGestureListener - Android Development - GestureDetector.OnGestureListener or GestureDetector.SimpleOnGestureListener 从扩展MainActivity的类中调用public void - Call public void from class that extends MainActivity 错误:类 SplashScreen 是公共的,应该在名为 SplashScreen.java 的文件中声明 public class SplashScreen extends AppCompatActivity - error: class SplashScreen is public, should be declared in a file named SplashScreen.java public class SplashScreen extends AppCompatActivity 实现并扩展一个类 - implements and extends a class 与阶级斗争,扩展和实施 - struggling with class, extends and implements Class 扩展和实现 - Class extends and implements 从扩展 Fragment 的类启动 AppCompatActivity Activity - Starting an AppCompatActivity Activity from a class that extends Fragment 将A.Class传递到公共B(Class <? extends C> )当A实现C - Pass A.Class into public B(Class<? extends C>) when A implements C 为什么我不能在我的“公共 class 适配器扩展 PagerAdapter”到 MainActivity2s - Why I cant make an intent in my “public class adapter extends PagerAdapter” to MainActivity2s
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM