Android for sliding and up-slide events

Source: Internet
Author: User

Did the development of the slide to refresh and loading are not unfamiliar, because we will be used in many times, that the effect on how to achieve it? Believe that a lot of small partners, today I will lead you together through third-party components to quickly achieve the above effect, categorization malleability every small partner can quickly get started. First for everyone to share:

Slide Refresh:

  

Up-Slide Loading:

  

Third-party resources: https://github.com/Maxwin-z/XListView-Android, after downloading the good resources, we begin to design the implementation:

We unzip the downloaded package, and then copy the six files in the package to the project six files are:

  

Our activity:

 Public classMainactivityextendsActivityImplementsixlistviewlistener{PrivateXlistview Mlistview; PrivateArrayadapter<string>Madapter; Privatearraylist<string> items =NewArraylist<string>(); PrivateHandler Mhandler; Private intstart = 0;//Data Start Location    Private Static intrefreshcnt = 0;//The first few refreshes        PrivateDate Date =NewDate (); PrivateSimpleDateFormat format =NewSimpleDateFormat ("yyyy mm month DD Day HH:mm:ss");//format the update time@Overrideprotected voidonCreate (Bundle savedinstancestate) {Super. OnCreate (savedinstancestate);        Setcontentview (R.layout.activity_main);        Geneitems (); Mlistview=(Xlistview) Findviewbyid (R.id.xlistview); Mlistview.setpullloadenable (true);//set drop-down refresh//mlistview.setpullloadenable (false);//settings cannot be loaded more actions//mlistview.setpullrefreshenable (false);//setting cannot perform refresh operationMadapter=NewArrayadapter<string> ( This, R.layout.xlist_item, items);        Mlistview.setadapter (Madapter); Mlistview.setrefreshtime (Format.format (date));//Set Update TimeMlistview.setxlistviewlistener ( This); Mhandler=NewHandler (); }        Private voidGeneitems () { for(inti = 0; I! = 20; ++i) {Items.Add ("Refresh cnt" + (+ +)start)); }    }    Private voidonLoad () {Mlistview.stoprefresh ();        Mlistview.stoploadmore (); Date=NewDate (); Mlistview.setrefreshtime (Format.format (date));//Set Update Time    }        //Slide Refresh@Override Public voidOnrefresh () {mhandler.postdelayed (NewRunnable () {@Override Public voidRun () {Start= ++refreshcnt;                Items.clear (); Mainactivity. This. Geneitems ();                Madapter.notifydatasetchanged (); Mainactivity. This. OnLoad (); }        }, 2000); }    //up-Slide loading@Override Public voidOnloadmore () {mhandler.postdelayed (NewRunnable () {@Override Public voidrun () {mainactivity. This. Geneitems ();                Madapter.notifydatasetchanged (); Mainactivity. This. OnLoad (); }        }, 2000); }    }

Main layout file Action_main.xml:

<linearlayout xmlns:android= "http://schemas.android.com/apk/res/android"    android:layout_width= " Fill_parent "    android:layout_height=" Fill_parent "    android:orientation=" vertical "      android:background= "#f0f0f0" >    <me.maxwin.view.XListView        android:id= "@+id/ Xlistview "        android:layout_width=" Fill_parent "        android:layout_height=" Fill_ Parent "         android:cachecolorhint=" #00000000 ">    </me.maxwin.view.xlistview></ Linearlayout>

OK, our project has been completed, we can run the operation.

Android for sliding and up-slide events

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.