Drop-down refresh, using the Android-pulltorefresh,github--https://github.com/chrisbanes/android-pulltorefresh
Simple ways to use Pulltorefresh
1. Download the relevant Lib from GitHub and import it into ADT
Download Down is these files
Then import to ADT, 4 projects after import
Launcheractivity
Pulltorefreshlistfragment
Pulltorefreshviewpager
Library
If after the introduction, the project has red error, click the Project Right button-"properties-" Android, in the library, the wrong library removed, and then click the Add button, re-add on it.
2. Create a new project, if the new project console appears SUPPORT.V4 package version inconsistent information, the new project V4 are copied and replaced the downloaded Lib V4
Use of 3.PullToRefresh
In the XML file
1 <LinearLayoutxmlns:android= "Http://schemas.android.com/apk/res/android"2 Xmlns:tools= "Http://schemas.android.com/tools"3 Android:layout_width= "Match_parent"4 Android:layout_height= "Match_parent"5 Android:paddingbottom= "@dimen/activity_vertical_margin"6 Android:paddingleft= "@dimen/activity_horizontal_margin"7 Android:paddingright= "@dimen/activity_horizontal_margin"8 Android:paddingtop= "@dimen/activity_vertical_margin"9 android:orientation= "vertical"Ten Tools:context= "Com.lijingbo.learnpulltorefruse.MainActivity" > One A <Com.handmark.pulltorefresh.library.PullToRefreshListViewAndroid:id= "@+id/lv" - Android:layout_width= "Match_parent" - Android:layout_height= "Match_parent"/> the - </LinearLayout>
In the Java file
1 Public classMainactivityextendsActivity {2 PrivateArrayadapter<string>adapter;3 PrivatePulltorefreshlistview LV;4 PrivateList<string>data;5 PrivateHandler handler=NewHandler () {6 @Override7 Public voidhandlemessage (Message msg) {8 //TODO auto-generated Method Stub9 Switch(msg.what) {Ten Case1: OneData.add ("Tianjin"); AData.add ("Xi ' an"); - Lv.onrefreshcomplete (); - Break; the default: - Break; - } - } + }; - + @Override A protected voidonCreate (Bundle savedinstancestate) { at Super. OnCreate (savedinstancestate); - Setcontentview (r.layout.activity_main); - -data =NewArraylist<string>(); -Data.add ("Nanjing"); -Data.add ("Shanghai"); inData.add ("Chengde"); - tolv=(Pulltorefreshlistview) Findviewbyid (r.id.lv); +adapter =NewArrayadapter<string>(Getapplicationcontext (), Android. R.layout.simple_list_item_1, data); - Lv.setadapter (adapter); theLv.setonrefreshlistener (NewOnrefreshlistener<listview>() { * $ @OverridePanax Notoginseng Public voidOnrefresh (pulltorefreshbase<listview>Refreshview) { - //TODO auto-generated Method Stub the NewThread (NewRunnable () { + A @Override the Public voidrun () { + //TODO auto-generated Method Stub - Try { $Thread.Sleep (3000); $}Catch(interruptedexception e) { - //TODO auto-generated Catch block - e.printstacktrace (); the } -Message msg =NewMessage ();WuyiMsg.what = 1; the handler.sendmessage (msg); - } Wu }). Start (); - } About }); $ } - -}
Pulltorefreshlistview mainly uses:
1. Locate the drop-down refresh control by using the Findviewbyid () method
2. Set the adapter, then use the Setadapter () method to bind the adapter and data list
3. Using the onrefreshlistener<listview> () listener, rewrite the listener's Onrefresh () method,
4. Set the listener using the Setonrefreshlistener () method.
The 5.onRefresh () method implements asynchronous processing through handler.
Android Development Control-android-pulltorefresh