Did the development of the slide to refresh and loading are not unfamiliar, because we will be used in many times, that the effect on how to achieve it? Believe that a lot of small partners, today I will lead you together through third-party components to quickly achieve the above effect, categorization malleability every small partner can quickly get started. First for everyone to share:
Slide Refresh:
Up-Slide Loading:
Third-party resources: https://github.com/Maxwin-z/XListView-Android, after downloading the good resources, we begin to design the implementation:
We unzip the downloaded package, and then copy the six files in the package to the project six files are:
Our activity:
Public classMainactivityextendsActivityImplementsixlistviewlistener{PrivateXlistview Mlistview; PrivateArrayadapter<string>Madapter; Privatearraylist<string> items =NewArraylist<string>(); PrivateHandler Mhandler; Private intstart = 0;//Data Start Location Private Static intrefreshcnt = 0;//The first few refreshes PrivateDate Date =NewDate (); PrivateSimpleDateFormat format =NewSimpleDateFormat ("yyyy mm month DD Day HH:mm:ss");//format the update time@Overrideprotected voidonCreate (Bundle savedinstancestate) {Super. OnCreate (savedinstancestate); Setcontentview (R.layout.activity_main); Geneitems (); Mlistview=(Xlistview) Findviewbyid (R.id.xlistview); Mlistview.setpullloadenable (true);//set drop-down refresh//mlistview.setpullloadenable (false);//settings cannot be loaded more actions//mlistview.setpullrefreshenable (false);//setting cannot perform refresh operationMadapter=NewArrayadapter<string> ( This, R.layout.xlist_item, items); Mlistview.setadapter (Madapter); Mlistview.setrefreshtime (Format.format (date));//Set Update TimeMlistview.setxlistviewlistener ( This); Mhandler=NewHandler (); } Private voidGeneitems () { for(inti = 0; I! = 20; ++i) {Items.Add ("Refresh cnt" + (+ +)start)); } } Private voidonLoad () {Mlistview.stoprefresh (); Mlistview.stoploadmore (); Date=NewDate (); Mlistview.setrefreshtime (Format.format (date));//Set Update Time } //Slide Refresh@Override Public voidOnrefresh () {mhandler.postdelayed (NewRunnable () {@Override Public voidRun () {Start= ++refreshcnt; Items.clear (); Mainactivity. This. Geneitems (); Madapter.notifydatasetchanged (); Mainactivity. This. OnLoad (); } }, 2000); } //up-Slide loading@Override Public voidOnloadmore () {mhandler.postdelayed (NewRunnable () {@Override Public voidrun () {mainactivity. This. Geneitems (); Madapter.notifydatasetchanged (); Mainactivity. This. OnLoad (); } }, 2000); } }
Main layout file Action_main.xml:
<linearlayout xmlns:android= "http://schemas.android.com/apk/res/android" android:layout_width= " Fill_parent " android:layout_height=" Fill_parent " android:orientation=" vertical " android:background= "#f0f0f0" > <me.maxwin.view.XListView android:id= "@+id/ Xlistview " android:layout_width=" Fill_parent " android:layout_height=" Fill_ Parent " android:cachecolorhint=" #00000000 "> </me.maxwin.view.xlistview></ Linearlayout>
OK, our project has been completed, we can run the operation.
Android for sliding and up-slide events