We all want to make lists that can refresh the items in the list with that fancy swipe up on the screen, to have some spinner animated, and to do some stuff after the list is refreshed. We can accomplish it by implementing the Swipe Refresh layout in to our project.

NOTE: We are going to use ButterKnife library for binding views:

First we need to add the dependency for the Swipe Refresh and RecyclerView (optional) in to our app gradle.build:

Then in our activity_main.xml we add the layout:

Then i our MainActivity we implement the functionality of the Swipe Refresh feature:

After binding the views with Butterknife library, we then set the color for the swipRefresh layout (two ways described in the code above), and we add listener to hear when swipe down from top action is performed on the display. In the overriden onRefresh() method we add our logic what to do when we refresh the list (refresh the items).

With setRefreshing(boolean) we show and hide the spinner animation. Default is shown.

With setSize(int) we set only two sizes of the Swipe Refresh, DEFAULT and LARGE.

This are the basic thing that this Swipe Refresh layout can do. For more information you should check official google documentaion:

Google SwipeRefreshLayout Documentation

 

 

Spread the love

1 Comment

  1. Neat blog! Is your theme custom made or did you download it from somewhere? A theme like yours with a few simple adjustements would really make my blog jump out. Please let me know where you got your design. Bless you|

Leave a Reply

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