Introduction to the Android swiperefreshlayout Drop-down Refresh Control

Source: Internet
Author: User

The following app basically has the function of Drop-down refresh, used to basically use Xlistview or write a drop-down refresh, the recent Google provides an official Drop-down refresh control swiperefreshlayout, I feel good ah, see accustomed to the traditional Drop-down refresh, This is a refreshing sensation (the seemingly-known app already uses this drop-down refresh).

Google also gave the V4 Compatibility Pack on the official website:



Let's take a look at the code in the layout file (I've got a ListView here. Of course you can put other controls as long as you're happy.)

 <android.support.v4.widget.swiperefreshlayout         android:
Id= "@+id/main_srl_bloglist"         android:layout_width= "Fill_parent"         android:layout_height= "Fill_parent" >          <listview              android:id= "@+id/main_lv_bolg_list"              android:layout_width= "Fill_parent"              android:layout_height= "Fill_parent"              android:divider= "#00000000"              android:dividerheight= "5DP" ></ListView>     </ Android.support.v4.widget.swiperefreshlayout>


finally take a look at the code in Activiy (here I use the androidannotations so I don't write findviewbyid haha)

 //set the color of the animation when refreshed, you can set 4          Mswiperefreshlayout.setcolorschemeresources (Android. R.color.holo_blue_light, android. R.color.holo_red_light, android. R.color.holo_orange_light, android.
R.color.holo_green_light);         mswiperefreshlayout.setonrefreshlistener (new  Swiperefreshlayout.onrefreshlistener ()  {              @Override             public void  onrefresh ()  {              
  mIndex=1;                 
Mbloglist.clear ();                 loadblogdata ()
;              }         }); 


It's good to call a method to get the data in Onrefresh. Don't forget to modify the status

Mswiperefreshlayout.setrefreshing (FALSE);

haha before to write tons of code with Swiperefreshlayout on these lines of code is not very convenient.



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.