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 calledonRequestDisallowInterceptTouchEvent(boolean)
. This method needs to be implemented by every class which implement theOnItemTouchListener
interface.So just add this method with an empty body...
... and have a look on interfaces in the Java language: https://docs.oracle.com/javase/tutorial/java/concepts/interface.html
the interface you are implementing has three methods. You are implementing already two of them. You need to add but not
which is called when a child of
RecyclerView
does not wantRecyclerView
and its ancestors to intercept touch events with. You can simply addto your class