Android Pulltorefreshlistview Pull-up refresh and drop-down refresh

Source: Internet
Author: User

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

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.