Android Open Source - SampleAndroidL Recycler Item Click Listener

From Project

Back to project page SampleAndroidL.


The source code is released under:

GNU General Public License

If you think the Android project SampleAndroidL listed in this page is inappropriate, such as containing malicious code/tools or violating the copyright, please email info at java2s dot com, thanks.

Java Source Code

/*from   w ww .  ja  va  2 s  .co  m*/
import android.content.Context;
import android.view.GestureDetector;
import android.view.MotionEvent;
import android.view.View;
public class RecyclerItemClickListener implements RecyclerView.OnItemTouchListener { 
  private OnItemClickListener mListener;
  public interface OnItemClickListener { 
    public void onItemClick(View view, int position);
  GestureDetector mGestureDetector;
  public RecyclerItemClickListener(Context context, OnItemClickListener listener) {
    mListener = listener;
    mGestureDetector = new GestureDetector(context, new GestureDetector.SimpleOnGestureListener() {
      @Override public boolean onSingleTapUp(MotionEvent e) {
        return true; 
  @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.getChildPosition(childView));
    return false; 
  @Override public void onTouchEvent(RecyclerView view, MotionEvent motionEvent) { }

Java Source Code List