Swipe Refresh Layout in Android

Last support library update has included an interesting and unexpected Swipe Refresh Layout: SwipeRefresLayout. It is a standard way to implement the common Pull to Refresh pattern in Android.

The SwipeRefreshLayout should be used whenever the user can refresh the contents of a 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.

 

Using this new layout is really easy, but here it is a simple guide to make it work in a few seconds.

Methods are quite few:

  •  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.

Swipe Refresh Layout Example :

Activity_Main.Xml

MainActivity.java:

We just need to get the layout, and assign some colours and the listener. The refreshing listener is a post delayed handler.

Output :-

Swipe Refresh

About Jaimin Patel

I am a Web Developer. I have been blogging and researching since 1 years and like to share my knowledge and research with the world. Peace..!!

View all posts by Jaimin Patel →

Leave a Reply

Your email address will not be published. Required fields are marked *