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>