开发者

ListView Horizontal Fling Gesture

开发者 https://www.devze.com 2023-02-20 12:27 出处:网络
I have a listview that displays entries for a given date. There are buttons above the listview that allow you to increase/decrease the date. Everything works. What I\'m looking to do is replace those

I have a listview that displays entries for a given date. There are buttons above the listview that allow you to increase/decrease the date. Everything works. What I'm looking to do is replace those buttons and have the user swipe right/left to increase/decrease the date.

What's the best way to go about this? I don't care what item is swiped, often there will be no items in the listview for a given date, just as long as it happens on the listview area. I do开发者_如何学C have click and longclick listeners on the items already.


Just implement the OnGestureListener.

public class MyListActivity extends ListActivity implements OnGestureListener

Use a GestureDetector

GestureDetector detector = new GestureDetector(this, this);

Pass the touch event of the list to the GestureDetector

listView.setOnTouchListener(new OnTouchListener() {
    public boolean onTouch(View view, MotionEvent e) {
        detector.onTouchEvent(e);
        return false;
    }
});

And finally use the fling method to detect a gesture. You can use the velocity values to detect the direction of the movement.

public boolean onFling(MotionEvent e1, MotionEvent e2, float velocityX, float velocityY) {}
0

精彩评论

暂无评论...
验证码 换一张
取 消