Pulltorefresh This open source library has long been heard, but has been useless. As a classic open source library, I think it is necessary to know.
Open the Web address on GitHub: Https://github.com/chrisbanes/Android-PullToRefresh
As soon as the Web page opens, you'll see a big reminder that the project is no longer maintained:
Anyway, download it before you say:
After the download is unpacked, open the folder as shown:
Then import into the project as shown in: (where the pulltorefreshlistfragment and Pulltorefreshviewpager are in the folder "extras")
If Pulltorefreshlistfragment and Pulltorefreshviewpager error after import, it may be because the library package needs to be re-imported. Such as:
When you import these three projects without any errors, create a new Android project to use this open source library.
The new project is named "Zhj_pulltorefresh".
The three package pulltorefreshlistfragment,pulltorefreshviewpager,library that were previously added to the project are then imported.
The following error may appear in the console after pouring into the package:
This is because the SUPPORT-V4 package in the new project is caused by a different version of the SUPPORT-V4 package in the Pulltorefreshlistfragment,pulltorefreshviewpager.
To solve this problem, simply copy the SUPPORT-V4 package from "Zhj_pulltorefresh" to Pulltorefreshlistfragment,pulltorefreshviewpager. and replace the original SUPPORT-V4 package, you can.
The following is the start of the code in the new project:
The first is the layout file Main.xml:
<?XML version= "1.0" encoding= "Utf-8"?><LinearLayoutxmlns:android= "Http://schemas.android.com/apk/res/android"Android:layout_width= "Match_parent"Android:layout_height= "Match_parent"android:orientation= "vertical" > <Com.handmark.pulltorefresh.library.PullToRefreshListViewAndroid:id= "@+id/pull_listview"Android:layout_width= "Fill_parent"Android:layout_height= "Fill_parent" > </Com.handmark.pulltorefresh.library.PullToRefreshListView></LinearLayout>
Then there is mainactivity (the code is very small and relatively simple):
Public classMainactivityextendsActivity {pulltorefreshlistview lv; PrivateArrayadapter<string>adapter; @Overrideprotected voidonCreate (Bundle savedinstancestate) {Super. OnCreate (savedinstancestate); Setcontentview (R.layout.main); LV= (Pulltorefreshlistview) Findviewbyid (R.id.pull_listview);//Get the controlList<string> list=NewArraylist<string>(); List.add ("Sichuan Tuopu"); List.add ("Shanghai Tuopu"); //easy to set adapterAdapter=NewArrayadapter<string> ( This, Android. R.layout.simple_list_item_1,list); Lv.setadapter (adapter); //Listen for flush controls and "drop-down refresh" cannot occur if you do not listenLv.setonrefreshlistener (NewOnrefreshlistener<listview>() {@Override Public voidOnrefresh (pulltorefreshbase<listview>Refreshview) { //This is where asynchronous tasks are used to simulate getting data from the network. NewAsynctask<void, Void, void>() {@Overrideprotectedvoid Doinbackground (void ... arg0) {Try{Thread.Sleep (3000);//Thread Hibernation}Catch(interruptedexception e) {//TODO auto-generated Catch blockE.printstacktrace (); } return NULL; } protected voidOnPostExecute (Void result) {//to add new dataAdapter.addall ("newly Added data", "newly added data"); Lv.onrefreshcomplete (); }; }.execute (); } }); }}
The results are as follows:
This is quite simple and does not include the demo.
Simple use of the Android pulltorefresh drop-down refresh control