Created
August 14, 2015 07:34
-
-
Save florent37/f97261dea498725e926b to your computer and use it in GitHub Desktop.
RecyclerView.OnClick
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
public class OnItemClickListener(){ | |
onItemClicked(int position, ViewHolder viewHolder); | |
} | |
recyclerView.addOnItemTouchListener(new RecyclerView.OnItemTouchListener() { | |
GestureDetector mGestureDetector; | |
@Override | |
public boolean onInterceptTouchEvent(RecyclerView view, MotionEvent e) { | |
View childView = view.findChildViewUnder(e.getX(), e.getY()); | |
if (childView != null && onItemClickListener != null) { | |
int position = view.getChildAdapterPosition(childView); | |
if (mGestureDetector == null) { | |
mGestureDetector = new GestureDetector(recyclerView.getContext(), new GestureDetector.SimpleOnGestureListener() { | |
@Override | |
public boolean onSingleTapUp(MotionEvent e) { | |
return true; | |
} | |
}); | |
} | |
if (mGestureDetector.onTouchEvent(e)) { | |
onItemClickListener.onItemClicked(position, view.getChildViewHolder(childView)); | |
return true; | |
} | |
return false; | |
} | |
@Override | |
public void onTouchEvent(RecyclerView rv, MotionEvent e) { | |
} | |
@Override | |
public void onRequestDisallowInterceptTouchEvent(boolean disallowIntercept) { | |
} | |
}); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment