2. Android's own drop-down refresh swiperefreshlayout--style 2

Source: Internet
Author: User

<Android.support.v4.widget.SwipeRefreshLayoutxmlns:android= "Http://schemas.android.com/apk/res/android"Android:id= "@+id/swipe_container"Android:layout_width= "Match_parent"Android:layout_height= "Match_parent" >    <ListViewAndroid:id= "@+id/list"Android:layout_width= "Match_parent"Android:layout_height= "Match_parent" /></Android.support.v4.widget.SwipeRefreshLayout>
3 ImportJava.lang.reflect.Field;4 Importjava.util.ArrayList;5 ImportAndroid.annotation.SuppressLint;6 Importandroid.app.Activity;7 ImportAndroid.os.Bundle;8 ImportAndroid.os.Handler;9 Importandroid.support.v4.widget.SwipeRefreshLayout;Ten ImportAndroid.util.DisplayMetrics; One ImportAndroid.view.View; A ImportAndroid.view.ViewTreeObserver; - ImportAndroid.widget.ListView; -  the  Public classMainactivityextendsActivityImplements - Swiperefreshlayout.onrefreshlistener { -  -     Privateswiperefreshlayout swipelayout; +     PrivateListView ListView; -     PrivateListviewadapter Adapter; +     PrivateArraylist<javabean>list; A     Private intNumber = 0; at  -     protected voidonCreate (Bundle savedinstancestate) { -         Super. OnCreate (savedinstancestate); -          - Setcontentview (r.layout.activity_main); -  inSwipelayout =(swiperefreshlayout) Findviewbyid (r.id.swipe_container); -Swipelayout.setonrefreshlistener ( This); to Swipelayout.setcolorscheme (Android. R.color.holo_blue_bright, + Android. R.color.holo_green_light, - Android. R.color.holo_orange_light, the Android. R.color.holo_red_light); *  $Viewtreeobserver vto =swipelayout.getviewtreeobserver ();Panax NotoginsengVto.addongloballayoutlistener (NewViewtreeobserver.ongloballayoutlistener () { -@SuppressLint ("Newapi") the              Public voidongloballayout () { +                 FinalDisplaymetrics metrics =getresources () A . Getdisplaymetrics (); theFloat Mdistancetotriggersync =Math.min ( +(View) swipelayout.getparent ()). GetHeight () * 0.6f, -500 *metrics.density); $                 Try { $Field field = Swiperefreshlayout.class -. Getdeclaredfield ("Mdistancetotriggersync"); -Field.setaccessible (true); the field.setfloat (Swipelayout, mdistancetotriggersync); -}Catch(Exception e) {Wuyi e.printstacktrace (); the                 } -  WuViewtreeobserver Obs =swipelayout.getviewtreeobserver (); -Obs.removeongloballayoutlistener ( This); About             } $         }); -  -List =NewArraylist<javabean>(); -List.add (NewJavaBean (0, "Item0")); AListView =(ListView) Findviewbyid (r.id.list); +adapter =NewListviewadapter ( This, list); the Listview.setadapter (adapter); -     } $  the      Public voidOnrefresh () { the         NewHandler (). postdelayed (NewRunnable () { the              Public voidrun () { theSwipelayout.setrefreshing (false); -List.add (NewJavaBean (++number, "Item" +Number )); in adapter.notifydatasetchanged (); the             } the}, 1000); About     } the}

2. Android's own drop-down refresh swiperefreshlayout--style 2

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.