Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Swipe detection for each row of listview

Tags:

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

like image 900
Farhan Khurshid Avatar asked Jul 06 '11 14:07

Farhan Khurshid


1 Answers

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
    }
}
like image 58
Nerijus Gedrimas 'Nereus Calm' Avatar answered Sep 30 '22 21:09

Nerijus Gedrimas 'Nereus Calm'