The Pulltorefreshlistview implementation of pull-up and pull-down refreshes has two steps:
1. Set the refresh mode
Pulltorefreshview.setmode (PullToRefreshBase.Mode.BOTH); // Flush at both ends Pulltorefreshview.setmode (PullToRefreshBase.Mode.PULL_FROM_START); // Pull-up refresh Pulltorefreshview.setmode (PullToRefreshBase.Mode.PULL_FROM_END); // Drop-down refresh
2, if the pull-up refresh or pull-down refresh needs to implement the Onrefreshlistener interface , if it is both ends refreshed, then Setonrefreshlistener need to implement OnRefreshListener2 Interface
Both ends of the refresh implementation:
Pulltorefreshview =(Pulltorefreshlistview) View.findviewbyid (R.id.pull_to_refresh_listview); Pulltorefreshview.setmode (PullToRefreshBase.Mode.BOTH);//flush at both ends//Pulltorefreshview.setmode (PullToRefreshBase.Mode.PULL_FROM_START);//Pull-up refresh//Pulltorefreshview.setmode (PullToRefreshBase.Mode.PULL_FROM_END);//Drop-down refreshPulltorefreshview.setonrefreshlistener (NewPulltorefreshbase.onrefreshlistener2<listview>() {@Override Public voidOnpulldowntorefresh (pulltorefreshbase<listview>Refreshview) {Refreshtype=Refresh_type_down; Refreshview.getloadinglayoutproxy (). Setrefreshinglabel ("Loading"); Refreshview.getloadinglayoutproxy (). Setpulllabel ("Drop-down load more"); Refreshview.getloadinglayoutproxy (). Setreleaselabel ("Release Start Loading");//refreshview.getloadinglayoutproxy (). Setlastupdatedlabel ("Last Load Time:"); //Do work to refresh the list here. Newgetdatatask (). Execute (); } @Override Public voidOnpulluptorefresh (pulltorefreshbase<listview>Refreshview) {Refreshtype=refresh_type_up; Refreshview.getloadinglayoutproxy (). Setrefreshinglabel ("Loading"); Refreshview.getloadinglayoutproxy (). Setpulllabel ("Pull up load more"); Refreshview.getloadinglayoutproxy (). Setreleaselabel ("Release Start Loading");//refreshview.getloadinglayoutproxy (). Setlastupdatedlabel ("Last Load Time:"); //Do work to refresh the list here. Newgetdatatask (). Execute (); } });
Asynctask Implementing asynchronous Loading
Private classGetdatataskextendsAsynctask<void, Void, string[]>{@Overrideprotectedstring[] Doinbackground (Void ... params) {Try{Thread.Sleep (3000); } Catch(interruptedexception e) {e.printstacktrace (); } return NewString[0]; } @Overrideprotected voidOnPostExecute (string[] result) {//Call Onrefreshcomplete when the list has been refreshed.Pulltorefreshview.onrefreshcomplete (); if(Refresh_type_down = =Refreshtype) {Article Article=Newarticle (); Article.settitle ("Drop-down Refresh add title"); Adapter.insert (article,0);//adapter is a linkedlist}Else if(Refresh_type_up = =Refreshtype) {Article Article=Newarticle (); Article.settitle ("Pull up Refresh add title"); Adapter.add (article); } Super. OnPostExecute (Result); } }
If you want to achieve a richer effect, you can modify the layout file parameters, such as:
<!--ptr:ptrdrawable= "@drawable/default_ptr_flip" ptr:ptranimationstyle= "Flip" Flip: Flip R Otate: Rotate - <!--ptr:ptrshowindicator= "True" arrow appears in the lower right corner of the upper right corner - <Com.handmark.pulltorefresh.library.PullToRefreshListViewAndroid:id= "@+id/pull_to_refresh_listview"Android:layout_height= "Fill_parent"Android:layout_width= "Fill_parent"Ptr:ptrshowindicator= "true"Android:background= "#CCC" />
Android Pulltorefreshlistview Pull-up refresh and drop-down refresh