Android new SwipeRefreshLayout control tutorial

Source: Internet
Author: User

Android new SwipeRefreshLayout control tutorial

SwipeRefreshLayout is a Google-style refresh control implemented by google after the PullToRefresh-ListView and ActionBarPullToRefresh, which features a strong google flavor.



After migrating to Android studio, you must use AppCompat_v7 21 +. After switching, you will find some interesting changes. For example, this SwipeRefreshLayout will evolve into a circle.


Let's take a look at how to use SwipeRefreshLayout! <喎?http: www.bkjia.com kf ware vc " target="_blank" class="keylink"> VcD4KPHA + pc9wpgokytfpyndo0qru2rk8vtba78pmyfnd96o6cjxwp1_vcd4kpha + PHByZSBjbGFzcz0 = "brush: java;">


Then you need to initialize the control in the code

  swipeRefreshLayout.setColorSchemeResources(android.R.color.holo_purple, android.R.color.holo_blue_bright, android.R.color.holo_orange_light,                android.R.color.holo_red_light);        swipeRefreshLayout.setOnRefreshListener(this);
Here, the circle sets several colors to replace the display, and then sets the listener to implement the onRefresh method of implements SwipeRefreshLayout. OnRefreshListener interface.
 @Override    public void onRefresh() {        adapter.sync();    }


In this way, the SwipeRefreshLayout control can be displayed in the drop-down list. However, the actual requirement is generally to load network requests, which is also very simple. SwipeRefreshLayout during the start request. setRefreshing (true); Call swipeRefreshLayout when the request is complete. setRefreshing (false );

So much? Yes, it's easy. You no longer have to endure the three dependency packages of ActionBarPullToRefresh and the compatibility issues in AppCompat_v7 21.


Let's talk about another question,

android.support.v4.widget.SwipeRefreshLayout
You do not need to use it in the heel layout, but there must be only one internal control, and you can slide it, such as listview and Scrollview. If a slide exception occurs, refer to the following link:
Https://yassirh.com/2014/05/how-to-use-swiperefreshlayout-the-right-way/

Slide Problem



Related Article

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.