Android swiperefreshlayout Official dropdown Refresh Control Introduction

Source: Internet
Author: User

The following app basically has a drop-down refresh function, used to basically use Xlistview or write a drop-down refresh, recently Google provides an official drop-down refresh control swiperefreshlayout, I feel good ah, see accustomed to the traditional drop-down refresh, It's a refreshing feeling (the app that seems to know is already using this drop-down refresh).

Google also gives the V4 Compatibility Pack on the official website:

By the way, take a look at the API chant:

and Xlistview similar, is very convenient to use, probably on these 4 commonly used methods, the following a simple example.

1. layout file:

[HTML]View Plaincopy
  1. <relativelayout xmlns:android="http://schemas.android.com/apk/res/android"
  2. android:layout_width="match_parent"
  3. android:layout_height="match_parent" >
  4. <android.support.v4.widget.SwipeRefreshLayout
  5. android:id="@+id/id_swipe_ly"
  6. android:layout_width="match_parent"
  7. android:layout_height="match_parent" >
  8. <ListView
  9. android:id="@+id/id_listview"
  10. android:layout_width="match_parent"
  11. android:layout_height="match_parent" >
  12. </ListView>
  13. </android.support.v4.widget.SwipeRefreshLayout>
  14. </relativelayout>


2, Mainactivty:

[Java]View Plaincopy
  1. Package Com.zhy.swiperefreshlayoutdemo;
  2. Import java.util.ArrayList;
  3. Import Java.util.Arrays;
  4. Import java.util.List;
  5. Import Android.annotation.SuppressLint;
  6. Import android.app.Activity;
  7. Import Android.os.Bundle;
  8. Import Android.os.Handler;
  9. Import Android.support.v4.widget.SwipeRefreshLayout;
  10. Import Android.util.Log;
  11. Import Android.widget.ArrayAdapter;
  12. Import Android.widget.ListView;
  13. Public class Mainactivity extends Activity implements Swiperefreshlayout.onrefreshlistener
  14. {
  15. private static final int refresh_complete = 0x110;
  16. private Swiperefreshlayout mswipelayout;
  17. private ListView Mlistview;
  18. private arrayadapter<string> Madapter;
  19. private List<string> Mdatas = new Arraylist<string> (Arrays.aslist ("Java", "Javascript", "C + +", "Ruby", "Json" ,
  20. "HTML"));
  21. private Handler Mhandler = new Handler ()
  22. {
  23. public void Handlemessage (android.os.Message msg)
  24. {
  25. switch (msg.what)
  26. {
  27. Case Refresh_complete:
  28. Mdatas.addall (Arrays.aslist ("Lucene", "Canvas", "Bitmap"));
  29. Madapter.notifydatasetchanged ();
  30. Mswipelayout.setrefreshing (false);
  31. Break ;
  32. }
  33. };
  34. };
  35. @SuppressLint ("Inlinedapi")
  36. protected void OnCreate (Bundle savedinstancestate)
  37. {
  38. super.oncreate (savedinstancestate);
  39. Setcontentview (R.layout.activity_main);
  40. Mlistview = (ListView) Findviewbyid (R.id.id_listview);
  41. Mswipelayout = (swiperefreshlayout) Findviewbyid (R.id.id_swipe_ly);
  42. Mswipelayout.setonrefreshlistener (this);
  43. Mswipelayout.setcolorscheme (Android. R.color.holo_blue_bright, Android. R.color.holo_green_light,
  44. Android. R.color.holo_orange_light, Android. R.color.holo_red_light);
  45. Madapter = New Arrayadapter<string> (this, Android.  R.layout.simple_list_item_1, Mdatas);
  46. Mlistview.setadapter (Madapter);
  47. }
  48. public void Onrefresh ()
  49. {
  50. //LOG.E ("xxx", Thread.CurrentThread (). GetName ());
  51. //UI Thread
  52. Mhandler.sendemptymessagedelayed (Refresh_complete, 2000);
  53. }
  54. }


Well, at the end, I feel pretty good, so try it.

OK ~

SOURCE Click here to download

From: http://blog.csdn.net/lmj623565791/article/details/24521483

Android swiperefreshlayout Official dropdown Refresh Control Introduction

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.