i have a listview and implemented onclick and also onfling.problem is when i do fling(swipe left to right), onclick event of listview is also getting executed.How to overCome this problem? how to differentiate touch(tap) and fling(swipe) in listview?
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;
}
}
P.S. Is it possible? to comment the OnClickListener of ListView and writing the same logic in any onTouchEvent? but still I have no doubt that onFling will call onTouch. Am I right?
See Question&Answers more detail:
os 与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…