[Switch] Google's swiperefreshlayout pull-down refresh usage

Source: Internet
Author: User

Swiperefreshlayout is a pull-down refresh component updated by Google in the support V4 19.1 library, making it easier to refresh.

Use:

1. First download the latest android-support-v4.jar version, the previous version is not swiperefreshlayout drop-down refresh control, if updated, this step can be omitted.

2. InXMLFile ReferenceAndroid. Support. v4.widget. swiperefreshlayoutControls, which can be placed with any controls, such as listview and gridview.

 1     <android.support.v4.widget.SwipeRefreshLayout   2         android:id="@+id/swipe_refresh"   3         android:layout_width="match_parent"   4         android:layout_height="match_parent" >   5        6         <ListView   7             android:id="@+id/listview"   8             android:layout_width="match_parent"   9             android:layout_height="match_parent" >  10         </ListView>  11     </android.support.v4.widget.SwipeRefreshLayout>  

 

3. Use it in a Java file.

1/** 2 * Home Page 3 * @ author W. W 4 */5 public class mainactivity extends activity implements swiperefreshlayout. onrefreshlistener {6 7/** 8 * Add a drop-down refresh 9 */10 private swiperefreshlayout swipelayout to the listview; 11 12/* 13 * listview 14 */15 private listview; 16 17/** 18 * listview adapter 19 */20 private listviewadapter adapter; 21 22 private list <iteminfo> infolist; 23 24 @ override 25 protected void oncreate (bundle savedinstancestate) {26 super. oncreate (savedinstancestate); 27 setcontentview (R. layout. activity_main); 28 29 swipelayout = (swiperefreshlayout) This. findviewbyid (R. id. swipe_refresh); 30 swipelayout. setonrefreshlistener (this); 31 32 // The top refresh style 33 swipelayout. setcolorscheme (Android. r. color. holo_red_light, android. r. color. holo_green_light, 34 android. r. color. holo_blue_bright, android. r. color. holo_orange_light); 35 36 infolist = new arraylist <iteminfo> (); 37 iteminfo info = new iteminfo (); 38 info. setname ("coin"); 39 infolist. add (Info); 40 listview = (listview) This. findviewbyid (R. id. listview); 41 adapter = new listviewadapter (this, infolist); 42 listview. setadapter (adapter); 43} 44 45 public void onrefresh () {46 new handler (). postdelayed (New runnable () {47 Public void run () {48 swipelayout. setrefreshing (false); 49 iteminfo info = new iteminfo (); 50 info. setname ("coin-refresh"); 51 infolist. add (Info); 52 adapter. notifydatasetchanged (); 53} 54}, 500); 55} 56}

Demo: http://download.csdn.net/detail/xue_wei_love/7135315

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.