我有一个listview并实现了onclick和onfling.problem是当我做fling(从左向右滑动)时,listview的onclick事件也被执行。如何克服这个问题?如何区分列表视图中的触摸(点击)和甩动(滑动)?
listClickListener = new OnItemClickListener() {
public void onItemClick(AdapterView<?> parent, View v,int position, long id) {
//Job of Onclick Listener
}
};
mContactList.setOnItemClickListener(listClickListener);
mContactList.setAdapter(adapter);
// Gesture detection
gestureDetector = new GestureDetector(new MyGestureDetector(prosNos));
gestureListener = new View.OnTouchListener() {
public boolean onTouch(View v, MotionEvent event) {
if (gestureDetector.onTouchEvent(event)) {
return true;
}
return false;
}
};
mContactList.setOnTouchListener(gestureListener);
}
public class MyGestureDetector extends SimpleOnGestureListener {
@Override
public boolean onFling(MotionEvent e1, MotionEvent e2, float velocityX, float velocityY) {
// My fling event
return false;
}
}
PS有可能吗?评论 ListView 的 OnClickListener 并在任何 onTouchEvent 中编写相同的逻辑?但我仍然毫不怀疑 onFling 会调用 onTouch。我对吗?