Android: perfectly solves the conflict between setonitemclicklistener and setontouchlistener of listview.

Source: Internet
Author: User

Android: perfectly solves the conflict between setonitemclicklistener and setontouchlistener of listview.

@ Overridepublic boolean onTouch (View v, MotionEvent event) {createVelocityTracker (event); switch (event. getAction () {case MotionEvent. ACTION_DOWN: xDown = event. getRawX (); break; case MotionEvent. ACTION_MOVE: xMove = event. getRawX (); // The distance from the activity to int distanceX = (int) (xMove-xDown); // you can call this operation to obtain the int xSpeed = getScrollVelocity (); // when the sliding distance is greater than our set minimum distance and the instantaneous sliding speed is greater than our set speed, return to the previous activityif (distanceX> XDISTANCE_MIN & xSpeed> XSPEED_MIN) {finish (); // set the switchover animation, which is displayed on the right and exits on the left. // overridePendingTransition (R. anim. in_from_left, R. anim. out_to_right);} else {return false;} break; case MotionEvent. ACTION_UP: recycleVelocityTracker (); break; default: break;} return false; // return false to respond to the click Event}
At the end, return false to respond to the click event, which perfectly resolves the event conflict issue !!!!!

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.