Android swiperefreshlayout Official dropdown Refresh Control Introduction

Source: Internet
Author: User

Reprint please indicate source: http://blog.csdn.net/lmj623565791/article/details/24521483

The following app basically has a drop-down refresh function, has basically used Xlistview or write a drop-down refresh, recently Google has provided an official drop-down refresh control swiperefreshlayout, I feel good ah, see accustomed to the traditional drop-down refresh, It's a refreshing sensation (the app that looks like it has been refreshed with this sort of pull-down).

Google also gives the V4 Compatibility Pack on the official site:


By the way, take a look at the API chant:


and Xlistview almost the same, or very convenient to use, about the 4 frequently used methods, the following paste a simple example.

1. layout file:

<relativelayout xmlns:android= "http://schemas.android.com/apk/res/android"    android:layout_width= "Match_ Parent "    android:layout_height=" match_parent ">    <android.support.v4.widget.swiperefreshlayout        Android:id= "@+id/id_swipe_ly"        android:layout_width= "match_parent"        android:layout_height= "Match_parent" >        <listview            android:id= "@+id/id_listview"            android:layout_width= "Match_parent"            android: layout_height= "Match_parent" >        </ListView>    </android.support.v4.widget.swiperefreshlayout ></RelativeLayout>

2, Mainactivty:

Package Com.zhy.swiperefreshlayoutdemo;import Java.util.arraylist;import Java.util.arrays;import java.util.List; Import Android.annotation.suppresslint;import Android.app.activity;import Android.os.bundle;import Android.os.handler;import Android.support.v4.widget.swiperefreshlayout;import Android.util.Log;import Android.widget.arrayadapter;import Android.widget.listview;public class Mainactivity extends Activity implements swiperefreshlayout.onrefreshlistener{private static final int refresh_complete = 0x110;private swiperefreshlayout Mswipelayout;private ListView mlistview;private arrayadapter<string> madapter;private List<String> Mdatas = new Arraylist<string> (arrays.aslist ("Java", "Javascript", "C + +", "Ruby", "Json", "HTML"));p rivate Handler Mhandler = new Handler () {public void Handlemessage (android.os.Message msg) {switch (msg.what) {case Refresh_ COMPLETE:mDatas.addAll (Arrays.aslist ("Lucene", "Canvas", "Bitmap")); madapter.notifydatasetchanged (); Mswipelayout.setrefreshing (false); break;};}; @SuppressLint ("Inlinedapi") protected void OnCreate (Bundle savedinstancestate) {super.oncreate (savedinstancestate); Setcontentview (r.layout.activity_main); Mlistview = (ListView) Findviewbyid (r.id.id_listview); mswipelayout = ( Swiperefreshlayout) Findviewbyid (R.id.id_swipe_ly); Mswipelayout.setonrefreshlistener (this); Mswipelayout.setcolorscheme (Android. R.color.holo_blue_bright, Android. R.color.holo_green_light,android. R.color.holo_orange_light, Android. R.color.holo_red_light); madapter = new Arrayadapter<string> (this, Android. R.layout.simple_list_item_1, Mdatas); Mlistview.setadapter (Madapter);} public void Onrefresh () {//LOG.E ("xxx", Thread.CurrentThread (). GetName ());//UI Threadmhandler.sendemptymessagedelayed (Refresh_complete, 2000);}}

Well, the end, I feel very good, it is best to try.




OK ~


Source code click here to download

Android swiperefreshlayout Official dropdown Refresh Control Introduction

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.