Android dropdown Refresh control using the third-party open source control implementation

Source: Internet
Author: User

The third-party drop-down refresh control used this time is: Android-pull-refresh,: Https://github.com/chrisbanes/Android-PullToRefresh

This control applies to:

    • Viewpager
    • Horizontalscrollview
    • ScrollView
    • WebView
    • Gridview
    • Listview
    • Expandablelistview
    • Listfragment

after downloading the extract from GitHub, after importing the Library,pulltorefreshlistfragment,pulltorefreshviewpager project, right-click on your new project, select Properties, After entering the page, click Add:
once added, you can start writing your demo with the following code:
<?xml version= "1.0" encoding= "Utf-8"? ><linearlayout xmlns:android= "http://schemas.android.com/apk/res/ Android "Android:layout_width=" Fill_parent "android:layout_height=" fill_parent "android:orientation=" vertical "&G    T <!--the Pulltorefreshlistview replaces a standard ListView widget. --<com.handmark.pulltorefresh.library.pulltorefreshlistview xmlns:ptr= "Http://schemas.android.com/apk/re S-auto "android:id=" @+id/pull_refresh_list "android:layout_width=" Fill_parent "android:layout_height= "Fill_parent" android:cachecolorhint= "#00000000" android:divider= "#19000000" android:dividerheight= "4         DP "android:fadingedge=" None "Android:fastscrollenabled=" false "android:footerdividersenabled=" false " Android:headerdividersenabled= "false" android:smoothscrollbar= "true" ptr:ptrdrawable= "@drawable/ic_l Auncher "ptr:ptrmode=" both "/></linearlayout>

Import Java.util.arraylist;import java.util.list;import Android.app.activity;import Android.os.asynctask;import Android.os.bundle;import Android.widget.arrayadapter;import Android.widget.listview;import android.widget.Toast; Import Com.handmark.pulltorefresh.library.pulltorefreshbase;import Com.handmark.pulltorefresh.library.pulltorefreshbase.onlastitemvisiblelistener;import Com.handmark.pulltorefresh.library.pulltorefreshbase.onrefreshlistener;import com.handmark.pulltorefresh.library.pulltorefreshlistview;/** * Mainactivity---implemented with a third-party pull-down refresh control * @author seabear * */ public class Mainactivity extends Activity {private Pulltorefreshlistview mpulltorefreshlistview;private list< string> marraylist = new arraylist<string> ();p rivate arrayadapter<string> mArrayAdapter;private int mnums = 0; @Overrideprotected void onCreate (Bundle savedinstancestate) {super.oncreate (savedinstancestate); Setcontentview (r.layout.activity_main); Mpulltorefreshlistview = (Pulltorefreshlistview) This.findVIewbyid (r.id.pull_refresh_list); marrayadapter = new Arrayadapter<> (this, Android. R.layout.simple_list_item_1, marraylist); Mpulltorefreshlistview.setadapter (Marrayadapter); Mpulltorefreshlistview.setonrefreshlistener (New onrefreshlistener<listview> () {@Overridepublic void Onrefresh (pulltorefreshbase<listview> Refreshview) {//TODO auto-generated method Stubnew Getdatatask (). Execute ();}});} Private class Getdatatask extends Asynctask<void, void, string>{@Overrideprotected String doinbackground (void ... params) {//simulates a background job.mnums++;try {thread.sleep ()} catch (Interruptedexception e) {}return "+" + Str Ing.valueof (mnums) + "line";} @Overrideprotected void OnPostExecute (String result) {Marraylist.add (result); Marrayadapter.notifydatasetchanged () ;//Call Onrefreshcomplete If the list has been refreshed.mPullToRefreshListView.onRefreshComplete (); Super.onpostexecute (result);}}}



Copyright NOTICE: This article for Bo Master original article, without Bo Master permission not reproduced.

Android dropdown Refresh control using the third-party open source control implementation

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.