Android SwipeRefreshLayout official pull-down refresh control introduction, android pull-down refresh

Source: Internet
Author: User

Android SwipeRefreshLayout official pull-down refresh control introduction, android pull-down refresh

Google provides an official pull-down refresh control, SwipeRefreshLayout. I personally feel pretty good! Thanks to the traditional pull-down refresh, this gives a fresh feeling (Gmail mailbox has already used this pull-down refresh ).

SwipeRefreshLayout is in the V4 package, and corresponding examples are also provided in the corresponding V4 Demo.

SwipeRefreshLayout can have only one direct sub-View, which may be a ListView, a Layout, or other components to be refreshed.

SetOnRefreshListener is used to listen for refreshing actions. The SwipeRefreshLayout drop-down will have a refreshing effect and trigger this listener.

If you need a refresh animation, setRefreshing (true), stop: setRefreshing (false)

If you want to disable refresh animation and gesture response, ssetEnable (false) and restore: setEnable (true)

Google also provides V4 compatibility packages on its official website:


Take a look at the API:


Similar to XlistView, It is very convenient to use. Here is a simple example of the four commonly used methods.

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. MHandler. sendEmptyMessageDelayed (REFRESH_COMPLETE, 2000 );
  51. }
  52. }

:



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


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.