The example of this article for everyone to share the Swiperefreshlayout refresh source, for your reference, the specific content as follows
1.SwipeRefreshLayout is Google's support V4 19.1 version of the library update of a drop-down refresh component, to achieve a more convenient refresh.
disadvantage : Only the dropdown
Sets the color Swipe_refresh_layout.setcolorschemeresources (Android) for refreshing control loops
. R.color.holo_blue_light, Android. R.color.holo_orange_light, Android. R.color.holo_red_light, Android. R.color.holo_green_light);
Sets the refresh control background color
Swipe_refresh_layout.setprogressbackgroundcolorschemecolor (getresources (). GetColor (Android). R.color.white));
Set sliding distance
Swipe_refresh_layout.setdistancetotriggersync (m);
Set the size mode
swipe_refresh_layout.setsize (swiperefreshlayout.default);
Sets the Drop-down refresh control state Hide
swipe_refresh_layout.setrefreshing (false);
2. Refer to the Android.support.v4.widget.SwipeRefreshLayout control in the XML file, where you can place any control, such as Listview,gridview.
<relativelayout xmlns:android= "http://schemas.android.com/apk/res/android"
android:layout_width= "Match_ Parent "
android:layout_height=" match_parent ">
<android.support.v4.widget.swiperefreshlayout
Android:id= "@+id/id_swipe_ly"
android:layout_width= "match_parent"
android:layout_height= "Match_parent" >
<listview
android:id= "@+id/id_listview"
android:layout_width= "Match_parent"
android: layout_height= "Match_parent" >
</ListView>
</android.support.v4.widget.swiperefreshlayout >
3.Java Code
public class Mainactivity extends activity implements Swiperefreshlayout.onrefreshlistener {private swiperefreshlayou
T swipelayout;
Private ListView ListView;
Private Listviewadapter adapter;
Private list<iteminfo> infolist;
@Override protected void OnCreate (Bundle savedinstancestate) {super.oncreate (savedinstancestate);
Setcontentview (R.layout.activity_main);
Swipelayout = (swiperefreshlayout) This.findviewbyid (R.id.swipe_refresh);
Swipelayout.setonrefreshlistener (this); Top-refreshed style Swipelayout.setcolorscheme (Android). R.color.holo_red_light, Android. R.color.holo_green_light, Android. R.color.holo_blue_bright, Android.
R.color.holo_orange_light);
Infolist = new arraylist<iteminfo> ();
ItemInfo info = new ItemInfo ();
Info.setname ("Coin");
Infolist.add (info);
ListView = (ListView) This.findviewbyid (R.id.listview);
adapter = new Listviewadapter (this, infolist);
Listview.setadapter (adapter); public void Onrefresh () {New HaNdler (). postdelayed (New Runnable () {public void run () {swipelayout.setrefreshing (false);
ItemInfo info = new ItemInfo ();
Info.setname ("Coin-refresh");
Infolist.add (info);
Adapter.notifydatasetchanged ();
}, 500); }
}
The above is the entire content of this article, I hope to help you learn, but also hope that we support the cloud habitat community.