Android Recyclerview Waterfall Stream swipe to last automatically load more

Source: Internet
Author: User

Mrecycleview.setonscrolllistener (NewRecyclerview.onscrolllistener () {//used to mark whether a slide is being made to the last, whether it is sliding down    BooleanIsslidingtolast =false; @Override Public voidOnscrollstatechanged (Recyclerview Recyclerview,intnewstate) {Staggeredgridlayoutmanager Manager=(Staggeredgridlayoutmanager) Recyclerview.getlayoutmanager (); //When you do not scroll        if(NewState = =recyclerview.scroll_state_idle) {            //gets the last fully displayed itemposition            int[] lastvisiblepositions = Manager.findlastvisibleitempositions (New int[Manager.getspancount ()]); intLastvisiblepos =Getmaxelem (lastvisiblepositions); intTotalitemcount =Manager.getitemcount (); //determine if scrolling to the bottom            if(Lastvisiblepos = = (totalItemCount-1) &&isslidingtolast) {                //load more-functional codeLN.E ("Howes right=" +manager.findlastcompletelyvisibleitemposition ()); Toast.maketext (Getactivitycontext (),"Load More", 0). Show (); } }} @Override Public voidOnscrolled (Recyclerview Recyclerview,intDxintdy) {        Super. onscrolled (recyclerview, DX, dy); //DX is used to determine the direction of transverse sliding, dy is used to determine the longitudinal direction        if(Dy > 0){            //greater than 0 indicates that scrolling downIsslidingtolast =true; }Else{            //less than or equal to 0 means stop or scroll upIsslidingtolast =false; }     }});
Private int getmaxelem (int[] arr) {        int size = arr.length;         int maxval = integer.min_value;          for (int i = 0; i < size; i++) {            if (arr[i]>maxval)                = arr[i ];        }         return maxval;}

Android Recyclerview Waterfall Stream swipe to last automatically load more

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.