且构网

分享程序员开发的那些事...
且构网 - 分享程序员编程开发的那些事

类必须声明为抽象还是?

更新时间:2022-10-17 13:26:02

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



空身... ...

  @Override 
public void onRequestDisallowInterceptTouchEvent(boolean disallowIntercept){
}

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

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

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

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) {
}

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