Android built-in pull-down refresh component Swiperefreshlayout

Source: Internet
Author: User

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

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.