Swiperefreshlayout feeling is that Google absorbed the pulltoRefresh-ListView, Actionbarpulltorefresh after the implementation of the Google-style refresh control, the colorful cross-bar, thick Google flavor.
After migrating to Android studio, you must use Appcompat_v7 21+, and after switching you will find some interesting changes, such as this swiperefreshlayout, evolved into a circle.
So let's see how to use the Swiperefreshlayout!
- First you need to declare in the layout:
<android.support.v4.widget.swiperefreshlayout xmlns:android= "Http://schemas.android.com/apk/res/android" android:id= "@+id/swipe_refresh_container" android:layout_width= "match_parent" android:layout_ height= "Match_parent" android:background= "#E4E4E4" ></android.support.v4.widget.swiperefreshlayout >
- Then you need to initialize the control in your 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 a number of colors to replace the display, then sets the listener to implement the Onrefresh method of the implements Swiperefreshlayout.onrefreshlistener interface
@Override public void Onrefresh () { adapter.sync (); }
In this case, the Swiperefreshlayout control is displayed when it is pulled down, but the actual requirements are usually loaded with the network request, then it is very simple, when the request start swiperefreshlayout.setrefreshing ( true); Call Swiperefreshlayout.setrefreshing (FALSE) when the request is complete;
Is that all? Yes, it's easy, no longer have to endure Actionbarpulltorefresh's three dependent packages, and compatibility issues in APPCOMPAT_V7 21.
Here's another question,
Android.support.v4.widget.SwipeRefreshLayout
It is not necessary to use in the layout, but it must have only one control inside, and if you can slide, such as Listview,scrollview, if you encounter a sliding exception, you can refer to the following link:
https://yassirh.com/2014/05/how-to-use-swiperefreshlayout-the-right-way/
Sliding problems
Android's new Swiperefreshlayout control tutorial