Android to determine the slide direction of the ListView

Source: Internet
Author: User

The code is very simple, to mlistview monitoring Onscrolllistener events, and then in onscroll to judge

The index of the first item in the ListView Private int mlistviewfirstitem = 0;//listview the position of the first item in the screen Private int  mscreeny = 0;//whether to scroll up private boolean misscrolltoup = false; @Overridepublic  void onscroll (abslistview abslistview, int firstvisibleitem,int  Visibleitemcount, int totalitemcount)  {if (Mlistview.getchildcount () >0) {boolean  isscrolltoup = false; View childat = mlistview.getchildat (Firstvisibleitem);int[] location = new  Int[2];childat.getlocationonscreen (location); LOG.D ("onscroll",  "firstvisibleitem= " +firstvisibleitem+ " , y=" +location[1]); if ( Firstvisibleitem!=mlistviewfirstitem) {if (Firstvisibleitem>mlistviewfirstitem) {LOG.E ("--->",  "swipe up") ; isscrolltoup = true;} ELSE{LOG.E ("--->",  "swipe Down"); isscrolltoup = false;} MLISTVIEWFIRSTITEM&NBSP;=&NBSP;FIRSTVISIBLEITEM;MSCREENY&NBSP;=&NBSP;LOCATION[1];} Else{iF (mscreeny>location[1]) {LOG.I ("--->",  "); isscrolltoup = true;} Else if (Mscreeny<location[1]) {LOG.I ("--->",  ", Slide Down"); isscrolltoup = false;} MSCREENY&NBSP;=&NBSP;LOCATION[1];} if (misscrolltoup!=isscrolltoup) {onscrolldirectionchanged (Misscrolltoup);}}} Private void onscrolldirectionchanged (Boolean isscrolltoup)  {}


Android to determine the slide direction of the ListView

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.