RecyclerVIew OnItemClick return -1
<p>I want to setup click handlers for views within the RecyclerView row. I want to handle item click from a fragment. I tried to code it by <a href="https://guides.codepath.com/android/Using-the-RecyclerView#overview" rel="nofollow">this tutorial</a>. But when I try to identify which view was clicked, it returns -1.</p>

<p>I have an inteface within my adapter.</p>

<pre><code>   public interface OnItemClickListener {
        void onItemClick(View itemView, int position);
    }
    public void setOnItemClickListener(OnItemClickListener listener) {
        this.mOnItemClickListener = listener;
    }
</code></pre>

<p>Then inside the ViewHolder constructor i call this:</p>

<pre><code>itemView.setOnClickListener(new View.OnClickListener() {
                @Override
                public void onClick(View v) {
                    if (mOnItemClickListener != null) {
                        mOnItemClickListener.onItemClick(v, getLayoutPosition());
                    }
                }
            });
</code></pre>

<p>And by last here is the part when i set the listener from my fragment:</p>

<pre><code>mFollowingAdapter.setOnItemClickListener(new FollowingAdapter.OnItemClickListener() {
            @Override
            public void onItemClick(View itemView, int position) {
                    Log.d(Constants.TAG, itemView.getId() + " " + position);
            }
        });
</code></pre>

<p>Full VIewHolder code:</p>

<pre><code>public class ViewHolder extends RecyclerView.ViewHolder {
        private ImageView request_author_profile;
        private TextView request_name;
        private ImageView request_accept;
        private ImageView request_decline;

        public ViewHolder(final View itemView) {
            super(itemView);
            request_author_profile = (ImageView) itemView.findViewById(R.id.profile_image);
            request_name = (TextView) itemView.findViewById(R.id.request_name);
            request_decline = (ImageView) itemView.findViewById(R.id.btn_request_decline);
            request_accept = (ImageView) itemView.findViewById(R.id.btn_request_accept);
            itemView.setOnClickListener(new View.OnClickListener() {
                @Override
                public void onClick(View v) {
                    if (mOnItemClickListener != null) {
                        mOnItemClickListener.onItemClick(itemView, getLayoutPosition());
                    }
                }
            });
        }
    }
</code></pre>

<p>Thanks for help.</p>