Tuesday, December 16, 2014

Android Pull to Refresh Layout

The SwipeRefreshLayout should be used whenever the user can refresh the contents of view via a vertical swipe gesture. the activity that instantiates this view should add an OnRefreshListener to be notified whenever the swipe to refresh gesture is completed. The SwipeRefreshLayout will notify the listener each and every time. The gesture is completed again. 

 setOnRefreshListener(OnRefreshListener): adds a listener to let other parts of the code know when refreshing begins.

 setRefreshing(boolean): enables or disables progress visibility.

 isRefreshing(): checks whether the view is refreshing.

 setColorScheme(): it receive four different colors that will be used to colorize the animation.

We begin implementing the Swipe to Refresh pattern with a brand new Android Studio project and the most recent version of the Android Support Library (your SDK manager should show an Android Support Library version of at least 21.0).
compile 'com.android.support:support-v4:21.0.+'



We just need to get the layout, and assign some colours and the listener. The refreshing listener is a post delayed handler.
protected void onCreate(Bundle savedInstanceState) {

    swipeLayout = (SwipeRefreshLayout) findViewById(R.id.swipe_container);

@Override public void onRefresh() {
    new Handler().postDelayed(new Runnable() {
        @Override public void run() {
    }, 5000);

No comments:

Post a Comment