Q:

How to implement swipe down gesture on a complete RecyclerView (not an item) in Android Studio?

I want to implement a swipe down gesture on a RecyclerView ina layout and not on the whole layout. 
My current code adds a gesture to the layout but doesn't work if I wipe down on the RecyclerView list.
package com.example.surajpatil.sp_gesturedemo;

   import android.support.v7.app.AppCompatActivity;
   import android.os.Bundle;
   import android.support.v7.widget.LinearLayoutManager;
   import android.support.v7.widget.RecyclerView;
   import android.view.GestureDetector.OnGestureListener;
   import android.view.GestureDetector;
   import android.view.MotionEvent;
   import android.widget.Toast;

   import java.util.ArrayList;

   public class MainActivity extends AppCompatActivity implements OnGestureListener 
   {

    MyRecyclerViewAdapter adapter;

    GestureDetector gestureDetector;

    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.activity_main);

        // data to populate the RecyclerView with
        ArrayList<String> roomNames = new ArrayList<>();
        roomNames.add("Hall");
        roomNames.add("Dinning");
        roomNames.add("Patio");
        roomNames.add("Bedroom");
        roomNames.add("Master Bedroom");
        roomNames.add("Kitchen");
        roomNames.add("Porch");
        roomNames.add("Hall Way");
        roomNames.add("Bathroom");

        // set up the RecyclerView
        RecyclerView recyclerView = findViewById(R.id.rvRooms);
        recyclerView.setLayoutManager(new LinearLayoutManager(this));
        adapter = new MyRecyclerViewAdapter(this, roomNames);
//        adapter.setClickListener(this);
        recyclerView.setAdapter(adapter);

        gestureDetector = new GestureDetector(MainActivity.this, MainActivity.this);
}

@Override
public boolean onDown(MotionEvent e) {
    return false;
}

@Override
public void onShowPress(MotionEvent e) {

}

@Override
public boolean onSingleTapUp(MotionEvent e) {
    return false;
}

@Override
public boolean onScroll(MotionEvent e1, MotionEvent e2, float distanceX, float distanceY) {
    return false;
}

@Override
public void onLongPress(MotionEvent e) {

}

@Override
public boolean onFling(MotionEvent motionEvent1, MotionEvent motionEvent2, float X, float Y) {

    if(motionEvent1.getY() - motionEvent2.getY() > 50){

        Toast.makeText(MainActivity.this , " Swipe Up " , Toast.LENGTH_LONG).show();

        return true;
    }

    if(motionEvent2.getY() - motionEvent1.getY() > 50){

        Toast.makeText(MainActivity.this , " Swipe Down " , Toast.LENGTH_LONG).show();

        return true;
    }

    if(motionEvent1.getX() - motionEvent2.getX() > 50){

        Toast.makeText(MainActivity.this , " Swipe Left " , Toast.LENGTH_LONG).show();

        return true;
    }

    if(motionEvent2.getX() - motionEvent1.getX() > 50) {

        Toast.makeText(MainActivity.this, " Swipe Right ", Toast.LENGTH_LONG).show();

        return true;
    }
    else {

        return true ;
    }

}@Override
public boolean onTouchEvent(MotionEvent motionEvent) {

    // TODO Auto-generated method stub

    return gestureDetector.onTouchEvent(motionEvent);
}

Please help me implement a swipe DOWN gesture on the RecyclerView, what code changes should I do?
I have two XML, one is the activity_main which has a RecyclerView, and another is the recyclerview_row. 
Apart from this, I have a MyRecyclerViewAdapter.java file, which creates, hold the view and bids the data.

A:

Subclass RecyclerView and create your customview then override onInterceptTouchEvent and listen gestures as below:
    @Override
    public boolean onInterceptTouchEvent(MotionEvent ev) {
        gestureDetector.onTouchEvent(ev);
        ...

UPDATE:
As a custom view example I created a boilerplate code for your case, I hope this will be an entry point to your customViews:
MyCustomRecyclerView.java
package com.example.myrecyclerview;

import android.content.Context;
import android.support.annotation.NonNull;
import android.support.annotation.Nullable;
import android.support.v4.view.GestureDetectorCompat;
import android.support.v7.widget.RecyclerView;
import android.util.AttributeSet;
import android.util.Log;
import android.view.GestureDetector;
import android.view.MotionEvent;

public class MyCustomRecyclerView extends RecyclerView {
private GestureDetectorCompat gestureDetector;

public MyCustomRecyclerView(@NonNull Context context) {
    super(context);
    init(context, null);

}

public MyCustomRecyclerView(@NonNull Context context, @Nullable AttributeSet attrs) {
    super(context, attrs);
    init(context, attrs);

}

public MyCustomRecyclerView(@NonNull Context context, @Nullable AttributeSet attrs, int defStyle) {
    super(context, attrs, defStyle);
}

private void init(Context context, AttributeSet attrs) {
    gestureDetector = new GestureDetectorCompat(context, gestureListener);
}

@Override
public boolean onInterceptTouchEvent(MotionEvent e) {
    gestureDetector.onTouchEvent(e);
    return super.onInterceptTouchEvent(e);

}

private final GestureDetector.OnGestureListener gestureListener = new GestureDetector.SimpleOnGestureListener() {
    @Override
    public boolean onScroll(MotionEvent e1, MotionEvent e2, float distanceX, float distanceY) {
        if (getParent() != null)
            getParent().requestDisallowInterceptTouchEvent(true);

        return true;
    }

    @Override
    public boolean onFling(MotionEvent e1, MotionEvent e2, float velocityX, float velocityY) {
        Log.i("TAG", "onFling: ");
        return super.onFling(e1, e2, velocityX, velocityY);
    }

    @Override
    public boolean onDown(MotionEvent e) {
        Log.i("TAG", "onDown: ");
        return super.onDown(e);
    }
};
}

And use it as below:
    <com.example.myproject.MyCustomRecyclerView
        android:layout_width="match_parent"
        android:layout_height="match_parent">
   </com.example.myproject.MyCustomRecyclerView>

