Skip to content

Instantly share code, notes, and snippets.

@florent37
Created August 14, 2015 07:34
Show Gist options
  • Save florent37/f97261dea498725e926b to your computer and use it in GitHub Desktop.
Save florent37/f97261dea498725e926b to your computer and use it in GitHub Desktop.
RecyclerView.OnClick
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