title: RecyclerView's OnItemClick triggering before its child's OnClick
body: <p>I am having some problems in my school project. My RecyclerView's <code>OnItemClick</code> is being triggered when I click on an ImageButton that is inside of it.</p>
  
  <p><code>CODE</code></p>
  
  <pre><code>mRecyclerView.addOnItemTouchListener(new RecyclerItemClickListener(this, mRecyclerView, new RecyclerItemClickListener.OnItemClickListener() {
    @Override
    public void onItemClick(View view, int position) {
      viewComments(posts.get(position));
    }
  
    @Override
    public void onItemLongClick(View view, int position) {
  
    }
  }));
  </code></pre>
  
  <p>And here's the RecyclerItemClickListener code:</p>
  
  <pre><code>public class RecyclerItemClickListener implements RecyclerView.OnItemTouchListener {
  
    private OnItemClickListener mListener;
    private GestureDetector mGestureDetector;
  
    public interface OnItemClickListener {
      void onItemClick(View view, int position);
  
      void onItemLongClick(View view, int position);
    }
  
    public RecyclerItemClickListener(Context context, final RecyclerView recyclerView, OnItemClickListener listener) {
      mListener = listener;
  
      mGestureDetector = new GestureDetector(context, new GestureDetector.SimpleOnGestureListener() {
        @Override
        public boolean onSingleTapUp(MotionEvent e) {
          View childView = recyclerView.findChildViewUnder(e.getX(), e.getY());
  
          if (childView.findViewById(R.id.btnRateUp).isPressed() || childView.findViewById(R.id.btnRateDown).isPressed()) {
            return false;
          }
  
          return true;
        }
  
        @Override
        public void onLongPress(MotionEvent e) {
          View childView = recyclerView.findChildViewUnder(e.getX(), e.getY());
  
          if (childView != null &amp;&amp; mListener != null) {
            mListener.onItemLongClick(childView, recyclerView.getChildAdapterPosition(childView));
          }
        }
      });
    }
  
    @Override
    public boolean onInterceptTouchEvent(RecyclerView view, MotionEvent e) {
      View childView = view.findChildViewUnder(e.getX(), e.getY());
  
      if (childView != null &amp;&amp; mListener != null &amp;&amp; mGestureDetector.onTouchEvent(e)) {
        mListener.onItemClick(childView, view.getChildAdapterPosition(childView));
      }
  
      return false;
    }
  
    @Override
    public void onTouchEvent(RecyclerView view, MotionEvent motionEvent) {
    }
  
    @Override
    public void onRequestDisallowInterceptTouchEvent(boolean disallowIntercept) {
    }
  }
  </code></pre>
  
  <p>This is what I came up with to detect if the child was getting the click,</p>
  
  <pre><code>if(childView.findViewById(R.id.btnRateUp).isPressed() || childView.findViewById(R.id.btnRateDown).isPressed())
  </code></pre>
  
  <p>but I have realized the method <code>isPressed()</code> takes longer than the RecyclerView's <code>OnItemClick</code> to process. The code only works when I don't tap on it quickly.</p>
  
  <p>btnRateUp and btnRateDown are ImageButtons and their <code>OnClick</code> events are being implemented in the Adapter's <code>onBindViewHolder</code> as follows:</p>
  
  <pre><code>holder.getBtnRateUp().setOnClickListener(new View.OnClickListener() {
    @Override
    public void onClick(View v) {
      doStuff(true);
    }
  });
  
  holder.getBtnRateDown().setOnClickListener(new View.OnClickListener() {
    @Override
    public void onClick(View v) {
      doStuff(false);
    }
  });
  </code></pre>