Q:

RecyclerView.OnItemTouchListener calls OnItemClick and onLongItemClick irregularly

I have been trying to implement simple click and Long click in my recyclerview but when i long press an item the onLongItemClick is executed twice once with correct position and once with position -1. Also on simple clicking, onLongItemClick is executed. Here's my code.
recyclerView.addOnItemTouchListener(new RecyclerItemClickListener(this, recyclerView, new RecyclerItemClickListener.OnItemClickListener() {
        @Override
        public void onItemClick(View view, int position) {

            if (shareMedia) {
                if (isMultiSelect)
                    Toast.makeText(SearchActivity.this, "Click Index: " + position + "\nMultiselect: " + isMultiSelect, Toast.LENGTH_SHORT).show();
                    if (position > -1) {
                        multi_select(position);
                    } else
                        Toast.makeText(getApplicationContext(), "Tap and hold to share", Toast.LENGTH_SHORT).show();

            }else{
                //Another Implementation
            }
        }

        @Override
        public void onItemLongClick(View view, int position) {
            if (!isMultiSelect) {
                SelectedListData = new ArrayList<MediaListingModel>();
                isMultiSelect = true;

                if (mActionMode == null) {
                    mActionMode = startActionMode(mActionModeCallback);
                }
            }
            Toast.makeText(SearchActivity.this, "Long Click Index: " + position + "\nMultiselect: " + isMultiSelect, Toast.LENGTH_SHORT).show();
            if(position > -1) {
                multi_select(position);
            }

        }
    }));

And the code for RecyclerItemClickListener.java is
public class RecyclerItemClickListener implements RecyclerView.OnItemTouchListener {
private OnItemClickListener mListener;

public interface OnItemClickListener {
    void onItemClick(View view, int position);

    void onItemLongClick(View view, int position);
}

private GestureDetector mGestureDetector;

public RecyclerItemClickListener(Context context, final RecyclerView recyclerView, OnItemClickListener listener) {
    mListener = listener;
    mGestureDetector = 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 && mListener != null) {
                mListener.onItemLongClick(child, recyclerView.getChildAdapterPosition(child));
            }
        }
    });
}

@Override
public boolean onInterceptTouchEvent(RecyclerView view, MotionEvent e) {
    View childView = view.findChildViewUnder(e.getX(), e.getY());
    if (childView != null && mListener != null && mGestureDetector.onTouchEvent(e)) {
        mListener.onItemClick(childView, view.getChildAdapterPosition(childView));
        return true;
    }
    return false;
}

@Override public void onTouchEvent(RecyclerView view, MotionEvent motionEvent) { }

@Override
public void onRequestDisallowInterceptTouchEvent (boolean disallowIntercept){}

}

A:

The error is maybe in your RecyclerItemClickListener.java. Try to remove the return true; in your if statement. 
@Override
public boolean onInterceptTouchEvent(RecyclerView view, MotionEvent e) {
    View childView = view.findChildViewUnder(e.getX(), e.getY());
    if (childView != null && mListener != null && mGestureDetector.onTouchEvent(e)) {
        mListener.onItemClick(childView, view.getChildAdapterPosition(childView));
    }
    return false;
}

Working with recycler view - tutorial

