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