Android Learning---drop-down refresh build

Source: Internet
Author: User

Google's official drop-down refresh build

Activity Code Implementation:

/**
* The swiperefreshlayout should be used whenever the user
* Can refresh the contents of a view via a vertical swipe gesture.
*
*/
public class Mainactivity extends Activity implements
Swiperefreshlayout.onrefreshlistener {
Private Swiperefreshlayout swipelayout;

protected void OnCreate (Bundle savedinstancestate) {
Super.oncreate (savedinstancestate);
Setcontentview (R.layout.activity_main);

Swipelayout = (swiperefreshlayout) Findviewbyid (R.id.swipe_container);
Classes that wish to being notified when the swipe gesture correctly
Triggers a refresh should implement this interface.
Swipelayout.setonrefreshlistener (this);
Swipelayout.setcolorscheme (Android. R.color.holo_blue_bright,
Android. R.color.holo_green_light,
Android. R.color.holo_orange_light,
Android. R.color.holo_red_light);
}

/**
* SwipeRefreshLayout.OnRefreshListener:Classes that wish to being notified when the swipe
* Gesture correctly triggers a refresh should implement this interface.
* and trigger this function;
*/
@Override
public void Onrefresh () {

New Handler (). postdelayed (New Runnable () {
@Override
public void Run () {
Notify the widget, the refresh state has changed.
Swipelayout.setrefreshing (FALSE);

}
}, 3000);
}

}

XML Implementation Activity_main.xml:

<android.support.v4.widget.swiperefreshlayout xmlns:android= "Http://schemas.android.com/apk/res/android"
Android:id= "@+id/swipe_container"
Android:layout_width= "Match_parent"
android:layout_height= "Match_parent" >

<scrollview
Android:layout_width= "Match_parent"
android:layout_height= "Match_parent" >

<textview
Android:layout_width= "Match_parent"
android:layout_height= "Wrap_content"
android:layout_margintop= "16DP"
android:gravity= "Center"
android:text= "@string/hello_world"/>
</ScrollView>

</android.support.v4.widget.SwipeRefreshLayout>

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.