Monitor the ListView in Android swipe to the bottom

Source: Internet
Author: User

The app in Android is to swipe down in the ListView to load more features, and don't judge in the Onscroll method, so that when you swipe to the bottom, maybe we need to trigger something, like load more, hide a control, and so on.

The first method is to swipe directly to the bottom to trigger

Listview.setonscrolllistener (New onscrolllistener () {       @Override        public void onscrollstatechanged (abslistview view, int  Scrollstate) {          //  When not scrolling            if  (Scrollstate == onscrolllistener.scroll_state_idle)  {              //  decide whether to scroll to the bottom               if  ( View.getlastvisibleposition ()  == view.getcount ()  - 1)  {                   //loading more versatile code                }           }      }  }); 

The second way is to swipe up 2 times to hide

/***  Scroll to the bottom of the list to read the next page of data */public class autoloadlistener implements onscrolllistener{     public interface AutoLoadCallBack {         void execute (String url);    }    private  int getlastvisibleposition = 0,lastvisiblepositiony=0;    private  Autoloadcallback  mcallback;    public autoloadlistener (AutoLoadCallBack  callback)     {        this.mcallback =  callback;    }    public void onscrollstatechanged ( Abslistview view, int scrollstate)  {        if   (Scrollstate == onscrolllistener.scroll_state_idle)  {             //Scroll to the bottom             if  ( View.getlastvisibleposition ()  ==  (View.getcount ()  - 1)  {                 view v= (View)   View.getchildat (View.getchildcount ()-1);                 int[] location = new  int[2] ;                 v.getlocationonscreen (location) ;//Get absolute coordinates over the entire screen                  int y=location [1];                 LOG.E ("x" +location[0], "Y" +location[1]);                 if  (vIew.getlastvisibleposition ()!=getlastvisibleposition                         &&  LASTVISIBLEPOSITIONY!=Y)//First drag to the bottom                  {                     toast.maketext (View.getcontext (),  "Drag again to the bottom to page", ". Show ();                      getlastvisibleposition=view.getlastvisibleposition ();                     lastVisiblePositionY=y;                      return;                }                 else if  (view.getlastvisibleposition () = = getlastvisibleposition                         && lastvisiblepositiony==y)//Drag to the bottom for the second time                 {                      Mcallback.execute (">>>>> Drag to Bottom");                 }            }             //does not scroll to the bottom, and the second time is initialized              getlastvisibleposition=0;             lastvisiblepositiony=0;        }    }     public void onscroll (Abslistview arg0, int arg1, int  ARG2, INT ARG3)  {    }}


Monitor the ListView in Android swipe to the bottom

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.