Swipe detection for each row of listview

19,512

Solution 1

Take a look into this answer and use pointToPosition method inside onFling Event

@Override
public boolean onFling(MotionEvent e1, MotionEvent e2, float velocityX, float velocityY) {
    try {
        Toast.makeText( listAdapter.getItem( listView.pointToPosition(Math.round(e1.getX()), Math.round(e1.getY())).toString());
        return super.onFling();
    } catch( Exception e ) {
        // do nothing
    }
}

Solution 2

I'm using the per item approach in my solution - take a look here My swipe detection code might be a bit different from standard swipe detection but it works perfectly for me. And I'm using attached tags to get the item related data. Hope that helps, but if you do have some questions just let me know and I'll try to explain in more detail.

Solution 3

As Per My Opinion is Use Boolean for the item,When that item is touched set as true,Using onTouchListener,

ListItem.setOnTouchListener(new View.OnTouchListener() {

        @Override
        public boolean onTouch(View arg0, MotionEvent event) {
            click=true;
            return click;


        }

    });`

Then You Can Override This:

 @Override
public boolean dispatchTouchEvent(MotionEvent ev){
super.dispatchTouchEvent(ev);
Log.v("Inside", "=====Dispatch Event===");
if(click){
    Log.v("Inside", "=====Dispatch Event=T==");
    click=false;
     return gestureDetector.onTouchEvent(ev);

}else{
    return false;
}

}
Share:
19,512
Farhan Khurshid
Author by

Farhan Khurshid

Updated on June 19, 2022

Comments

  • Farhan Khurshid
    Farhan Khurshid about 2 years

    I have a list of videos located in the sd-card. At this point, I just need help in creating gestures or swipe detection for each row in the list view. Thanks to this question at stackoverflow Fling gesture detection on grid layout, I implemented the gesture on the listview. It now easily detects when the user swipes in the right direction or left direction. But this gesture is for the entire listview. I just want to know how can I implement this swipe detection for individual rows. For example, the application now makes a toast that prints "Right Swipe", "Left Swipe". I just want to make it like "Right Swipe on row no 1", "Left Swipe on Row no 3" etc.. I hope my question was clear.

    Looking forward to some helpful replies. Thanks

  • Farhan Khurshid
    Farhan Khurshid almost 13 years
    SwipeView or ViewFlow are best used in those cases where we have different views. I have a single listView with several items appearing on the same page. I just want to get swipe gesture for each individual row.. Any other suggestions??