Android Dropdown Refresh official version of _android

Source: Internet
Author: User

There are also a lot of articles on the internet about the dropdown, but they are too long. Just found the official Drop-down Refresh library, and the effect is good, simple and beautiful, and very convenient to use.
Here is the effect chart:

My friend was empty and refreshed two more.

Use or very convenient, in the layout file to add Swiperefreshlayout, this is the Drop-down refresh layout.

I also joined a ListView in the Swiperefreshlayout because I was mainly using a drop-down refresh to update the contents of the ListView.
Layout file:

<relativelayout xmlns:android= "http://schemas.android.com/apk/res/android" 
  android:layout_width= "Match_ Parent " 
  android:layout_height=" match_parent "> 
 
  <android.support.v4.widget.swiperefreshlayout 
    Android:id= "@+id/id_swipe_ly" 
    android:layout_width= "match_parent" 
    android:layout_height= "Match_parent" > 
 
    <listview 
      android:id= "@+id/id_listview" 
      android:layout_width= "Match_parent" 
      android: layout_height= "Match_parent" > 
    </ListView> 
  </android.support.v4.widget.swiperefreshlayout > 
 
</RelativeLayout> 

As soon as the code is written here, a drop-down refresh appears as long as the main interface slides down to the top.

Then we're going to instantiate this Drop-down refresh layout, set what it's going to do when it refreshes, and when the refresh is done, the rotated icon disappears.

Mswipelayout = (swiperefreshlayout) Findviewbyid (r.id.haoyouliebiaoshuaxin);//Instantiate//handler to update the UI
                Haoyouhandler = new Handler () {@Override public void Handlemessage (msg) {

                Super.handlemessage (msg);
                The thing to do Item i1 = new Item ();
                I1.name = "hehe";
                I1.account = 25566;

                Haoyou.add (I1);
                Item i2 = new Item ();
                I2.name = "haha";

                I2.account = 25577;

                Haoyou.add (I2);

                Haoyouadpter = new Liebiaoadapter (Mainactivity.this, R.layout.liebiao, haoyou);
                  
                  
                    Haoyoulist.setadapter (Haoyouadpter);

              Cancels the updated animation mswipelayout.setrefreshing (false);
              
              
              }
            }; Set Listener Mswipelayout.setonrefreshlistener (new SWIPEREFRESHLAyout.

                Onrefreshlistener () {@Override//What code is executing when it is being updated public void Onrefresh () {
                    
                    New Thread (New Runnable () {@Override public void run () {
                    Wait one second try {thread.sleep (1000);
                    catch (Interruptedexception e) {e.printstacktrace ();
                    //Send a message to handler update UI messages OK = new ();



                  Haoyouhandler.sendmessage (OK);

 }). Start ();

I am in the listener's Onrefresh function, wait a second, and then send a message to handler to update the UI, update and then cancel the update.

The above is the entire content of this article, I hope to help you learn.

Related Article

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.