Skip to content

Instantly share code, notes, and snippets.

@jpardogo
Created October 19, 2016 13:44
Show Gist options
  • Save jpardogo/b98ffd01dc0b19e0564e5c51fef3119f to your computer and use it in GitHub Desktop.
Save jpardogo/b98ffd01dc0b19e0564e5c51fef3119f to your computer and use it in GitHub Desktop.
RecyclerItemClickListener
public class RecyclerItemClickListener implements RecyclerView.OnItemTouchListener {
private OnItemClickListener mListener;
private GestureDetector mGestureDetector;
public interface OnItemClickListener {
void onItemClick(View view, int position);
}
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.getChildAdapterPosition(childView));
return true;
}
return false;
}
@Override
public void onTouchEvent(RecyclerView view, MotionEvent motionEvent) {
}
@Override
public void onRequestDisallowInterceptTouchEvent(boolean disallowIntercept) {
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment