This is based on the latest V4 package implementation of a drop-down refreshed Dongdong ~ ~ ~
First of all, the whole is very simple, after all, is not a custom, but also please relax your heart!!! Not much nonsense to say, direct sticker code
PackageCom.bob.swiperefresh;ImportAndroid.app.Activity;ImportAndroid.os.Message;Importandroid.support.v4.widget.*;ImportAndroid.os.Bundle;ImportAndroid.widget.ArrayAdapter;ImportAndroid.widget.ListView;ImportJava.util.ArrayList;ImportJava.util.List;ImportAndroid.os.Handler;/*This is a drop-down refreshDemo1, first with the officialSwiperefreshlayoutto achieve it.___It 's so ugly to say */Public classMainactivityextendsActivityImplementsSwiperefreshlayout.onrefreshlistener {private intIndex=0;private static final intRefresh_finish=1; //sets the amount of markup that is completed for a refresh PrivateSwiperefreshlayoutMswipe;PrivateListviewListView;PrivateString[]Arrays=Newstring[]{"Hello", "I am a Student", "I Love Android", "Love Open Resource"};PrivateArrayadapter<string>Adapter;PrivateList<string>Data=NewArraylist<> ();//aslistis a bridge between the array and the collection and cannot be used directly for initializationListinterface variable, or it will collapse when the data is added. PrivateHandlerHandler=NewHandler () {@Override Public voidHandlemessage(Message msg) {Switch(Msg. What) { CaseRefresh_finish:Data. Add (GetData ()); Adapter. notifydatasetchanged ();//prompt data adapter data changes to update data in the adapter Mswipe. setrefreshing (false);//Hide Refresh progress bar Break ; } } }; PublicStringGetData() {//Loop to get information from an array String re =Arrays[Index]; Index= (Index+1) %Arrays.length;returnRe; }@Override protected voidonCreate(Bundle savedinstancestate) {Super. OnCreate (Savedinstancestate); Setcontentview (r.layout.Activity_main); Mswipe= (swiperefreshlayout) Findviewbyid (r.id.Swipe_ly); ListView= (ListView) Findviewbyid (r.id.LV); Adapter=NewArrayadapter<> (This ,Android. R.layout.simple_list_item_1, Data); ListView. Setadapter (Adapter); Mswipe. Setonrefreshlistener ( This); Mswipe. setcolorschemeresources (Android. R.color.Holo_blue_bright, Android. R.color.Holo_green_light, Android. R.color.Holo_orange_light, Android. R.color.Holo_red_light); //This sets the color options for loading animations, up to4species }@Override Public voidOnrefresh() {//This should be used: network access or other time-consuming operations on the side, and finally sendmessagejustOK //explain that thisDemoUpdate inUInot necessarily usedHandler, or you can update it here directlyUI, just without the effect of the delay, but in the //the project must still need a sub-thread to implement it . Handler. sendemptymessagedelayed (Refresh_finish, 4000);//send an empty message and add a delay time }/* public void Onrefresh () {//or in this way.new Handler (). postdelayed (New Runnable () {@OverridePublic void Run () {mswipe.setrefreshing (false); }},4000); }*/}
Layout file:
<relativelayoutxmlns:Android="Http://schemas.android.com/apk/res/android" xmlns:Tools="Http://schemas.android.com/tools" Android: Layout_width="Match_parent" Android: layout_height="Match_parent" Tools: context=". Mainactivity "><android.support.v4.widget.swiperefreshlayout Android: id="@+id/swipe_ly" Android: Layout_width="Match_parent" Android: layout_height="Match_parent" ><listview Android: id="@+id/lv" Android: Layout_width="Match_parent" Android: layout_height="Match_parent"></ListView></android.support.v4.widget.SwipeRefreshLayout></RelativeLayout>
The data is I a one to refresh out, the concrete implementation logic can be seen in the source code ~ ~ ~
As far as I know, if the V4 version of the effect is "know the client" that effect, now the latest this is currently used in the "Coursera" client, interested in the pot friends can see for themselves
(PS: Slag with Linux, for the moment have not found the more gratified gift recording tools, such as Bo friends have recommended, please leave a message to inform!!! Kneeling Thanks!!! )
GitHub Address
The official Android Swiperefreshlayout