问题描述
我试着去刷卡左,右一个列表视图,并得到viewflipper来等维护。就像remeberthemilk应用程序,默认的新闻和天气应用程序在Nexus One上(通过新闻话题刷卡)。使用各种教程香港专业教育学院发现,我遇到了在一个计算器,说明如何实现滑动手势
Im trying to swipe left and right on a listview and get the viewflipper to swtich. Just like the remeberthemilk app and the default news and weather app on the nexus one (Swiping through news topics). Using various tutorials ive found , i came across on one stackoverflow that shows how to implement a swipe gesture
class MyGestureDetector extends SimpleOnGestureListener {
@Override
public boolean onFling(MotionEvent e1, MotionEvent e2, float velocityX, float velocityY) {
try {
if (Math.abs(e1.getY() - e2.getY()) > SWIPE_MAX_OFF_PATH)
return true;
// right to left swipe
if(e1.getX() - e2.getX() > SWIPE_MIN_DISTANCE && Math.abs(velocityX) > SWIPE_THRESHOLD_VELOCITY) {
} else if (e2.getX() - e1.getX() > SWIPE_MIN_DISTANCE && Math.abs(velocityX) > SWIPE_THRESHOLD_VELOCITY) {
viewFlipper.setInAnimation(slideRightIn);
viewFlipper.setOutAnimation(slideRightOut);
viewFlipper.showPrevious();
}
} catch (Exception e) {
// nothing
}
return true;
}
}
和我做了这个工作。
lstView.setOnTouchListener(gestureListener);
不过有时会发生什么事是当人刷卡列表视图setOnItemClickListener就会被解雇。我该怎么办prevent这种情况的发生,而且只能得到setOnItemClickListener发射,当用户实际点击就可以了列表项目,而不只是刷卡就可以了。
However sometimes what would happen is the listview setOnItemClickListener would be fired when the person is swiping. How do i prevent this from happening, and only get the setOnItemClickListener fired when the user actually clicks on it list item and not just swiping on it.
谢谢,费萨尔阿比德
推荐答案
那么一个我发现的方法是不是依靠,onItemClick,我实现了。
Well one way I found is instead of relying on, onItemClick, I implemented
@Override
public boolean onSingleTapConfirmed(MotionEvent e) {
// TODO Auto-generated method stub
Log.e("Item Click", "Item Click");
return super.onSingleTapConfirmed(e);
}
里面SimpleOnGestureListener,它好像它的工作原理
Inside SimpleOnGestureListener and it seems as if it works
这篇关于里面viewflipper列表视图刷卡的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!