I have a recyclerview that has image, texts & image button, when I use the RecyclertouchListener and add onItemTouchListener it overclicks the button while the button has onclicklistener
If I don't handle clicklistener for the recyclerview, the button works fine. Only when the recyclerview has something to do in the onItemtouchListener.
public class RecyclerTouchListener implements RecyclerView.OnItemTouchListener{
private GestureDetector gestureDetector;
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.getChildAdapterPosition(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.getChildAdapterPosition(child));
return false;
}
@Override
public void onTouchEvent(RecyclerView rv, MotionEvent e) {
}
@Override
public void onRequestDisallowInterceptTouchEvent(boolean disallowIntercept) {
}
recyclerView.addOnItemTouchListener(new RecyclerTouchListener(getActivity(), recyclerView, new ClickListener() {
@Override
public void onClick(View view, int position) {
startActivity(new Intent(getActivity(), Show.class).putExtra("show", data.get(position)));
}
@Override
public void onLongClick(View view, int position) {
}
}));