The simple use of Android Recyclerview

Source: Internet
Author: User

The first is the main layout

<android.support.v4.widget.swiperefreshlayoutxmlns:android= "Http://schemas.android.com/apk/res/android" Android:id= "@+id/swiperefreshlayout" android:layout_width= "match_parent" android:layout_height= "Match_parent" > <android.support.v7.widget.recyclerview android:id= "@+id/recylerview" android:layout_width= "Wrap_ Content "android:layout_height=" Wrap_content "></android.support.v7.widget.recyclerview></ Android.support.v4.widget.swiperefreshlayout>

Then get the control and set the listener

findviewbyid......// Set drop-down refresh Swiperefreshlayout.setonrefreshlistener (New swiperefreshlayout.onrefreshlistener ()  {          @Override         public  void onrefresh ()  {            if ( isrefreshing) {//Determine if you are refreshing                &NBSP;&NBSP;LOG.D (TAG, "ignore manually update!") ;            } else{                  do.......             }        }     }); 

said pull refresh, then there are pull-up loads more, In fact, I think the pull-up load more recyclerview and swiperefreshlayout have not done very well, but also this control is not very comfortable place. A simple way to introduce

Recyclerview.setonscrolllistener (New recyclerview.onscrolllistener ()  {              @Override              public void onscrolled (Recyclerview recyclerview, int dx, int  dy)  {                 super.onscrolled (Recyclerview, dx, dy);                 int lastVisibleItem =  ((Linearlayoutmanager)   Mlayoutmanager). Findlastvisibleitemposition ();                 int totalitemcount = mlayoutmanager.getitemcount ();                 //lastvisibleitem  >= totalitemcount - 4  means that the remaining 4 item is loaded automatically, and you are free to choose                  // dy>0  means swipe down                  if  (lastvisibleitem >= totalitemcount -  4 && dy > 0)  {                     if (Isloadingmore) {                        &NBSP;&NBSP;&NBSP;LOG.D (TAG, "ignore manually update!");                      } else{                          loadpagE ();//Here The multithreading also need to manually control the isloadingmore                         isLoadingMore = false;                     }                 }             }        } );

Summarize:

1, the new control is very comfortable to use, but a lot of features are not all written well

2, expect the official solution pull load more problems

The simple use of Android Recyclerview

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.