Maybe the dropdown refreshes before you may use some third-party open source libraries, such as Pulltorefresh, Actionbar-pulltorefresh wait, but now some formal components---swiperefreshlayout, Swiperefreshlayout is a drop-down refresh component of Google's library update on the Support V4 19.1 version, which is very handy and makes it easy to refresh Google Now.
The use of the official comes with controls to ensure versatility and style. Swiperefreshlayout is inherited ViewGroup. To implement a pull-down refresh, which can include other components, and feel very easy to use afterwards.
<relativelayout xmlns:android= "http://schemas.android.com/apk/res/android" xmlns:tools= "http// Schemas.android.com/tools "android:layout_width=" match_parent "android:layout_height=" Match_parent "Android:paddi ngleft= "@dimen/activity_horizontal_margin" android:paddingright= "@dimen/activity_horizontal_margin" Android: paddingtop= "@dimen/activity_vertical_margin" android:paddingbottom= "@dimen/activity_vertical_margin" tools: context= "Com.example.myapplication2.app.MainActivity" > <android.support.v4.widget.swiperefreshlayout Andro Id:id= "@+id/swip" android:layout_width= "match_parent" android:layout_height= "match_parent" > <Li Stview android:id= "@+id/listview" android:layout_width= "Match_parent" Android:layout_heig ht= "Match_parent" > </ListView> </android.support.v4.widget.swiperefreshlayout></relati Velayout>
Import Android.os.handler;import Android.os.message;import Android.support.v7.app.actionbaractivity;import Android.support.v4.widget.swiperefreshlayout;import Android.support.v4.widget.swiperefreshlayout.onrefreshlistener;import Android.os.bundle;import Android.view.Menu ; Import Android.view.menuitem;public class Mainactivity extends actionbaractivity implements onrefreshlistener{privat e swiperefreshlayout swiperefreshlayout; Handler Handler = new Handler () {@Override public void Handlemessage (Message msg) {Super.handlem Essage (msg); Swiperefreshlayout.setrefreshing (FALSE); } }; @Override protected void OnCreate (Bundle savedinstancestate) {super.oncreate (savedinstancestate); Setcontentview (R.layout.activity_main); Swiperefreshlayout = (swiperefreshlayout) Findviewbyid (R.ID.SWIP); Swiperefreshlayout.setonrefreshlistener (this); Swiperefreshlayout.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); } @Override public void Onrefresh () {handler.sendemptymessagedelayed (1, 5000); }}
In addition, the above Onrefresh () feature is implemented to obtain data functionality and update data when you complete data updates, transfer swiperefreshlayout.setrefreshing (false); To turn off refresh.
Android built-in pull-down refresh component Swiperefreshlayout