1 <Android.support.v4.widget.SwipeRefreshLayout2 xmlns:android= "Http://schemas.android.com/apk/res/android"3 Android:id= "@+id/swipe_container"4 Android:layout_width= "Match_parent"5 Android:layout_height= "Match_parent" >6 <ListView7 Android:id= "@+id/listview"8 Android:layout_width= "Match_parent"9 Android:layout_height= "Wrap_content"Ten android:padding= "16DP" /> One </Android.support.v4.widget.SwipeRefreshLayout
3 Importjava.util.ArrayList;4 Importandroid.app.Activity;5 ImportAndroid.os.Bundle;6 ImportAndroid.os.Handler;7 Importandroid.support.v4.widget.SwipeRefreshLayout;8 ImportAndroid.widget.ArrayAdapter;9 ImportAndroid.widget.ListView;Ten One Public classMainactivityextendsActivityImplements A Swiperefreshlayout.onrefreshlistener { - - Privateswiperefreshlayout mswipelayout; the PrivateListView Mlistview; - Privatearraylist<string> list =NewArraylist<string>(); - - protected voidonCreate (Bundle savedinstancestate) { + Super. OnCreate (savedinstancestate); - Setcontentview (r.layout.activity_main); + AMlistview =(ListView) Findviewbyid (R.id.listview); atMlistview.setadapter (NewArrayadapter<string> ( This, - Android. R.layout.simple_list_item_1, - getData ()) - ); - -Mswipelayout =(swiperefreshlayout) Findviewbyid (r.id.swipe_container); inMswipelayout.setonrefreshlistener ( This); - //the random color of the turning circle to Mswipelayout.setcolorschemeresources (Android. R.color.holo_blue_bright, + Android. R.color.holo_green_light, Android. R.color.holo_orange_light, - Android. R.color.holo_red_light); the } * $ PrivateArraylist<string>GetData () {Panax NotoginsengList.add ("Hello"); -List.add ("This is Stormzhang"); theList.add ("An Android Developer"); +List.add ("Love Open Source"); AList.add ("My Github:stormzhang"); theList.add ("Weibo:googdev"); + returnlist; - } $ $ Public voidOnrefresh () { - NewHandler (). postdelayed (NewRunnable () { - @Override the Public voidrun () { -Mswipelayout.setrefreshing (false);Wuyi } the}, 5000); - } Wu}
1, Android's own drop-down refresh swiperefreshlayout