类必须声明为抽象的还是? [英] Class must either be declared abstract or?

查看:33
本文介绍了类必须声明为抽象的还是?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我是安卓新手.我一直使用片段来创建我的应用程序.所以我从这个 here.

I am new to android. I have always used snippets to create my app. So I copied material style drawer from this here.

现在我在这部分代码中遇到了一个问题:

Now I am facing a problem in this part of the code:

static class RecyclerTouchListener implements RecyclerView.OnItemTouchListener {

    private GestureDetector gestureDetector;
    private ClickListener clickListener;

    public RecyclerTouchListener(Context context, final RecyclerView recyclerView, final ClickListener clickListener) {
        this.clickListener = clickListener;
        gestureDetector = new GestureDetector(context, new GestureDetector.SimpleOnGestureListener() {
            @Override
            public boolean onSingleTapUp(MotionEvent e) {
                return true;
            }

            @Override
            public void onLongPress(MotionEvent e) {
                View child = recyclerView.findChildViewUnder(e.getX(), e.getY());
                if (child != null && clickListener != null) {
                    clickListener.onLongClick(child, recyclerView.getChildPosition(child));
                }
            }
        });
    }

    @Override
    public boolean onInterceptTouchEvent(RecyclerView rv, MotionEvent e) {

        View child = rv.findChildViewUnder(e.getX(), e.getY());
        if (child != null && clickListener != null && gestureDetector.onTouchEvent(e)) {
            clickListener.onClick(child, rv.getChildPosition(child));
        }
        return false;
    }

    @Override
    public void onTouchEvent(RecyclerView rv, MotionEvent e) {
    }
}

在这个片段中,它给出了错误.我可以给出图像错误

In this snippet it gives error . I can give image of error

我试图使类抽象,但随后它会干扰 oncreate 包代码.任何帮助将不胜感激

I tried to make the class abstract, but then it interferes with oncreate bundle code. Any help would be appreciated

推荐答案

这个消息告诉你,RecyclerView.OnItemTouchListener(它是一个接口)定义了一个名为 onRequestDisallowInterceptTouchEvent(boolean).这个方法需要被每个实现OnItemTouchListener接口的类实现.

This message tells you, that the RecyclerView.OnItemTouchListener (which is an interface) defines a method called onRequestDisallowInterceptTouchEvent(boolean). This method needs to be implemented by every class which implement the OnItemTouchListener interface.

所以只需添加一个空主体的方法...

So just add this method with an empty body...

@Override
public void onRequestDisallowInterceptTouchEvent(boolean disallowIntercept) {
}

... 并查看 Java 语言中的接口:https://docs.oracle.com/javase/tutorial/java/concepts/interface.html

... and have a look on interfaces in the Java language: https://docs.oracle.com/javase/tutorial/java/concepts/interface.html

这篇关于类必须声明为抽象的还是?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆