Nested ScrollView solution in Android ListView item _android

Source: Internet
Author: User

  Frontier: Sometimes, ListView item to display more fields, considering the display problem, the item has to be nested outside scrollview to achieve, so the problem comes, when ListView need to do click events, The Listvew Click event was intercepted because of ScrollView's nesting use: The ListView had to be rewritten to achieve it.

/** * * @author Author: Isea Star * * @da2016 year October 24: * * @toTODO Class Description: Resolve ListView nested Scrollview,scrollview Intercept ListView Item Click event Solution * * * nested ScrollView in ListView, found smooth vertical slide is normal, but cannot click ListView Item.
After querying the Android distribution mechanism to resolve, inherit ListView rewrite ListView's Onintercepttouchevent. * * Onintercepttouchevent Always call ListView ontouchevent Guarantee ListView events are performed, * super.onintercepttouchevent (EV)
does not intercept the horizontal slip that needs to be passed to the ScrollView. * * public class Mylistview extends ListView {private int flag = 0; private float startx; private float starty; public myl Istview (context) {Super [context];//TODO auto-generated constructor stub} public Mylistview Tributeset attrs, int defstyle) {Super (context, attrs, defstyle);//TODO auto-generated constructor stub} public MyList View (context, AttributeSet attrs) {Super (context, attrs);//TODO auto-generated constructor stub} @Override pub Lic boolean onintercepttouchevent (motionevent ev) {//Always invokes ListView touch event handling ontouchevent (EV); if (ev.getaction () = = Mot Ionevent.action_down) {startx = Ev.getx ();
Starty = Ev.gety ();
return false; } if (ev.getaction () = = Motionevent.action_move) {Float scollx = Ev.getx ()-startx; float scolly = Ev.gety ()-starty; /judge whether it is horizontal or vertical, or vertical, to block move events and up events (no interception will be performed simultaneously by ListView and ScrollView) if (Math.Abs (SCOLLX) < Math.Abs (scolly)) {flag = 1
;
return true;
return false; } if (ev.getaction () = = motionevent.action_up) {if (flag = = 1) {return true;} return false;} return SUPER.ONINTERCEPTT
Ouchevent (EV); }
}

The above is a small set to introduce the Android ListView of the item nested ScrollView solution, I hope to help you, if you have any questions please give me a message, small series will promptly reply to everyone. Here also thank you very much for the cloud Habitat Community website support!

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.