Created
September 3, 2017 20:32
-
-
Save wizlif/67772a15b48b9a735f436ed074a43c90 to your computer and use it in GitHub Desktop.
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
/** | |
* Created by root on 8/21/17. | |
*/ | |
public class RecyclerTouchListener implements RecyclerView.OnItemTouchListener { | |
private GestureDetector gestureDetector; | |
private ClickListener clickListener; | |
public RecyclerTouchListener(Context context, final RecyclerView recyclerView, final ClickListener clickListener) { | |
this.clickListener = clickListener; | |
gestureDetector = new GestureDetector(context, new GestureDetector.SimpleOnGestureListener() { | |
@Override | |
public boolean onSingleTapUp(MotionEvent e) { | |
return true; | |
} | |
@Override | |
public void onLongPress(MotionEvent e) { | |
View child = recyclerView.findChildViewUnder(e.getX(), e.getY()); | |
if (child != null && clickListener != null) { | |
clickListener.onLongClick(child, recyclerView.getChildPosition(child)); | |
} | |
} | |
}); | |
} | |
@Override | |
public boolean onInterceptTouchEvent(RecyclerView rv, MotionEvent e) { | |
View child = rv.findChildViewUnder(e.getX(), e.getY()); | |
if (child != null && clickListener != null && gestureDetector.onTouchEvent(e)) { | |
clickListener.onClick(child, rv.getChildPosition(child)); | |
} | |
return false; | |
} | |
@Override | |
public void onTouchEvent(RecyclerView rv, MotionEvent e) { | |
} | |
@Override | |
public void onRequestDisallowInterceptTouchEvent(boolean disallowIntercept) { | |
} | |
} | |
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
recyclerView.addOnItemTouchListener(new RecyclerTouchListener(this, recyclerView, new ClickListener() { | |
@Override | |
public void onClick(View view, int position) { | |
showEditDialog(position); | |
} | |
@Override | |
public void onLongClick(View view, int position) { | |
} | |
})); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment