"Pulltorefresh series one" Android pull-up loading drop-down refresh control in detail

Source: Internet
Author: User


Reprint Please specify: http://blog.csdn.net/duguang77/article/details/40921601

Author Information:

Pulltorefresh CONTROLS: Https://github.com/chrisbanes/Android-PullToRefresh

Https://github.com/chrisbanes

Baidu Network disk: HTTP://PAN.BAIDU.COM/S/1O6UMIFW



(a) Import method:

1. Import extras,library,sample into eclipse after download



2. You may get an error after importing, please change the dependent package location



(b) How to use: We generally use more is simple listview, of course, other situations such as gridview,webview, etc., the author also has a direct written control, we directly use the good


Let's take a look at the basic methods used
code for 1.XML layout files
<relativelayout xmlns:android= "http://schemas.android.com/apk/res/android"    xmlns:tools= "http// Schemas.android.com/tools "    android:layout_width=" match_parent "    android:layout_height=" Match_parent "    tools:context= "Com.example.testpulltoreresh.MainActivity" >    < Com.handmark.pulltorefresh.library.PullToRefreshListView        android:id= "@+id/pl_refresh"        android:layout_ Width= "Match_parent"        android:layout_height= "Match_parent"/></relativelayout>


2. Setting the Pulltorefresh Listener event
Mpulllist.setonrefreshlistener (New OnRefreshListener2 () {@Overridepublic void Onpulldowntorefresh ( Pulltorefreshbase Refreshview) {//drop-down refresh triggered event//Get formatted time string label = Dateutils.formatdatetime (Getapplicationcontext ( ), System.currenttimemillis (), Dateutils.format_show_time | Dateutils.format_show_date | Dateutils.format_abbrev_all);//Update Lastupdatedlabelrefreshview.getloadinglayoutproxy (). SetLastUpdatedLabel (Label )//////Open thread emulation interface fill data new Getdatatask (). Execute (); @Overridepublic void Onpulluptorefresh (Pulltorefreshbase refreshview) {//On Load triggered event///Open thread analog interface fill data new Getdatatask () . Execute ();}});


3. Set the drop-down, up-loading tips
Set the Pulltorefreshlistview mode Mpulllist.setmode (Mode.both);//Set the load prompt for Pullrefreshlistview on load Mpulllist.setmode ( Mode.both); Mpulllist.getloadinglayoutproxy (False, True). Setpulllabel ("pull-up loading ..."); mpulllist.getloadinglayoutproxy (False, True). Setrefreshinglabel ("Loading ..."); Mpulllist.getloadinglayoutproxy (False, True). Setreleaselabel ("Release load more .///Set Pullrefreshlistview load Prompt Mpulllist.getloadinglayoutproxy (true, false). Setpulllabel ("drop-down refresh ..."); Mpulllist.getloadinglayoutproxy (True, false). Setrefreshinglabel ("Loading ..."); Mpulllist.getloadinglayoutproxy (True , false). Setreleaselabel ("Loosen load more ...");






all code for my demo project
public class Mainactivity extends Activity {private Pulltorefreshlistview mpulllist;private linkedlist<string> Mlistitems;private arrayadapter<string> madapter;private string[] mstrings = {"I am very kind", "I am gentle", "I am Amoy", "I Am the Arirang", "I Is the big gray wolf, "I Am Sheep Sheep"}; @Overrideprotected void OnCreate (Bundle savedinstancestate) {super.oncreate (savedinstancestate); Setcontentview (R.layout.activity_main); Initview (); Seteventlistener (); InitData ();} /** * Initialize control */private void Initview () {mpulllist = (Pulltorefreshlistview) Findviewbyid (R.id.pl_refresh);} /** * Set listener */private void Seteventlistener () {Mpulllist.setonrefreshlistener (new OnRefreshListener2 () {@Overridepublic void Onpulldowntorefresh (Pulltorefreshbase refreshview) {//drop-down refresh triggered event//Get formatted time string label = Dateutils.formatdatetime (Getapplicationcontext (), System.currenttimemillis (), Dateutils.format_show_time | Dateutils.format_show_date | Dateutils.format_abbrev_all);//Update Lastupdatedlabelrefreshview.getloadinglayoutproxy (). SetLastUpdatedLabel (Label );///Turn on thread emulation interface fill data new Getdatatask (). Execute ();} @Overridepublic void Onpulluptorefresh (Pulltorefreshbase refreshview) {//On Load triggered event///Open thread analog interface fill data new Getdatatask () . Execute ();}}); /** * Initialize data */private void InitData () {//Set Pulltorefreshlistview mode Mpulllist.setmode (Mode.both);// Sets the load prompt Mpulllist.setmode (mode.both) on Pullrefreshlistview loading, Mpulllist.getloadinglayoutproxy (False, True). Setpulllabel ("Pull load ..."); Mpulllist.getloadinglayoutproxy (False, True). Setrefreshinglabel ("Loading ..."); Mpulllist.getloadinglayoutproxy (False, True). Setreleaselabel ("Loosen load more ...");// The load hint Mpulllist.getloadinglayoutproxy (true, false) is set when the Pullrefreshlistview drop-down is loaded. Setpulllabel ("drop-down refresh ..."); Mpulllist.getloadinglayoutproxy (True, false). Setrefreshinglabel ("Loading ..."); Mpulllist.getloadinglayoutproxy (True , false). Setreleaselabel ("Loosen load more ..."); mlistitems = new linkedlist<string> (); Mlistitems.addall (Arrays.aslist ( mstrings)); madapter = new Arrayadapter<string> (this, Android. R.layout.simple_list_item_1, mlistitems); mpulllist.seTadapter (Madapter);} Private class Getdatatask extends Asynctask<void, Void, string[]> {@Overrideprotected string[] Doinbackground ( Void ... params) {try {thread.sleep (n);} catch (Interruptedexception e) {}return null;} @Overrideprotected void OnPostExecute (string[] result) {if (Mpulllist.isheadershown ()) {Mlistitems.addfirst ("I am the newly incorporated concubine --drop-down Refresh ");} else if (Mpulllist.isfootershown ()) {mlistitems.addlast ("I am the concubine that put you back in your Arms");} Madapter.notifydatasetchanged ();//Call Flush complete mpulllist.onrefreshcomplete (); Super.onpostexecute (result);}}



Demo:http://pan.baidu.com/s/1c03tvve
Reprint Please specify: http://blog.csdn.net/duguang77/article/details/40921601


"Pulltorefresh series one" Android pull-up loading drop-down refresh control in detail

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.