1

I have a ListView with different types of rows. The row may contain text, image, video or something else. If I click on ImageView (inside the row) I will go to another activity to show the image in full screen, If I click on Video (inside the row) I will go to another activity to play he video.

I have implemented right to left swipe listener on my ListView. If I start the ListView swipe from an empty space in ListView, the swipe works (first and second row in below image). However if I start the ListView swipe from the ListView row's item, then the swipe doesn't work (third and fourth row in below image). If I remove the click events from ImageView and Video then the swipe works even if I start the swipe from the ListView row's item i.e. in this case the swipe works on whole ListView, no matter on which row I do the swipe.

enter image description here

How can I get rid on this problem? I think this can be achieved if I disable all the click events on the all the items inside ListView. How can do so? Is there any other way?

I want both swipe on ListView and click on ListView's item.

Nitesh Kumar
  • 5,370
  • 5
  • 37
  • 54

1 Answers1

0

Trick way, you can call item of listview's onTouchListener, when the Image or Video was clicked. Simply call imageview's onTouch method.

ImageView image; // your image view, and asuume the it is initialized.

row.setOnTouchListener(new View.OnTouchListener() {

@Override
public boolean onTouch(View v, MotionEvent event) {

    switch (event.getAction()) {

    case MotionEvent.ACTION_DOWN:                     
        image.onTouchEvent(event);
        break;                     
    }

    return false;
}

});

OR, It seems that, your image or video has it's own onTouchListener. The problem is, they consume the event and do not send them to it's parent view. So, do not return "true", and the event will be sent to it's parent.

Stanley Ko
  • 3,383
  • 3
  • 34
  • 60