This is my old question . However, this time I also provided my code.
I have a ListView with different types of strings. A string may contain text, image, video, or something else. If I click on the ImageView (inside the line), I will move on to another action to show the image in full screen. If I click on Video (inside the line), I will move on to another action to play its video.
I implemented listening to napkins from right to left in my ListView. If I start scrolling a ListView from white space into a ListView, the swipe works (first and second lines at the bottom of the image). However, if I started scrolling a ListView from a ListView row element, then the swipe does not work (the third and fourth rows at the bottom of the image). If I delete click events from ImageView and Video, then the swipe works even if I started scrolling from a ListView line item, i.e. In this case, the swipe will work throughout the ListView, regardless of which line I make the swipe.

How can I get rid of this problem? I think this can be achieved if I turn off all click events for all elements inside the ListView. How to do it? Is there another way?
I want to both scroll in the ListView and click on the ListView element.
SwipeDetector.java - ListView
public class SwipeDetector implements View.OnTouchListener {
private SwipeListener swipeListener;
private ListView mListView;
private int hundred;
private boolean motionInterceptDisallowed = false;
public static enum Action {
LR,
RL,
TB,
BT,
None
}
private static final int HORIZONTAL_MIN_DISTANCE = 30;
private static final int VERTICAL_MIN_DISTANCE = 80;
private float downX, downY, upX, upY;
private Action mSwipeDetected = Action.None;
public SwipeDetector(Context context, ListView listView) {
hundred = (int) context.getResources().getDimension(R.dimen.hundred);
mListView = listView;
}
public boolean swipeDetected() {
return mSwipeDetected != Action.None;
}
public Action getAction() {
return mSwipeDetected;
}
@Override
public boolean onTouch(View v, MotionEvent event) {
switch (event.getAction()) {
case MotionEvent.ACTION_DOWN:
{
downX = event.getX();
downY = event.getY();
mSwipeDetected = Action.None;
return false;
}
case MotionEvent.ACTION_MOVE:
{
upX = event.getX();
upY = event.getY();
float deltaX = downX - upX;
float deltaY = downY - upY;
float absX = Math.abs(deltaX);
float absY = Math.abs(deltaY);
if((absX >= (3 * absY)) && absX > HORIZONTAL_MIN_DISTANCE && mListView != null && !motionInterceptDisallowed) {
mListView.requestDisallowInterceptTouchEvent(true);
motionInterceptDisallowed = true;
}
if((absX >= (3 * absY)) && absX <= hundred) {
if (deltaX > 0) {
mSwipeDetected = Action.RL;
swipeListener.onSwipe(MotionEvent.ACTION_MOVE, Action.RL, absX);
}
}
return false;
}
case MotionEvent.ACTION_UP:
swipeListener.onSwipe(MotionEvent.ACTION_UP, Action.BT, 0);
if (mListView != null) {
mListView.requestDisallowInterceptTouchEvent(false);
motionInterceptDisallowed = false;
}
return false;
case MotionEvent.ACTION_CANCEL:
return true;
}
return false;
}
public void setSwipeListener(SwipeListener listener) {
swipeListener = listener;
}
public interface SwipeListener {
void onSwipe(int event, Action action, float x);
}
}
SwipeDetector ListView
final SwipeDetector swipeDetector = new SwipeDetector(SwipeActivity.this, mListView);
swipeDetector.setSwipeListener(mSwipeListener);
mListView.setOnTouchListener(swipeDetector);
SwipeDetector.SwipeListener
onSwipe()
@Override
public void onSwipe(int event, SwipeDetector.Action action, float x) {
switch (event) {
case MotionEvent.ACTION_MOVE:
System.out.println("list move");
break;
case MotionEvent.ACTION_UP:
System.out.println("list up");
break;
}
}
onClickListener() TextView, ImageView VideoView
holder.mTextView.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View v) {
System.out.println("item textview click");
}
});
holder.mImageView.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View v) {
System.out.println("item imageview click");
}
});
holder.mVideoView.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View v) {
System.out.println("item videoview click");
}
});
ListView, Swipe ListView . , TextView/ImageView/VideoView, onClickListener (ListView) onTouchListener().
? , , ListView, onClick , ListView, ListView onSwipe .