Android Pull or Swipe Down to Refresh Using SwipeRefreshLayout Example

Here you will learn about android pull or swipe down to refresh using SwipeRefreshLayout example.

You may have seen the pull to refresh feature in apps like Facebook, Twitter, Gmail, etc. We can implement that in android using SwipeRefreshLayout widget.

How to Implement?

Add SwipeRefreshLayout widget in your layout xml file with only one child. The child can be listview, gridview, recyclerview, etc.

Implement SwipeRefreshLayout.OnRefreshListener and override onRefresh() method. Whenever a pull or swipe down gesture is done the onRefresh() method is called. You have to do any update operation in this method. After completing update operation just call setRefreshing(false) method to remove the progress indicator.

Below I have shared one example in which I am updating the data of listview on swipe down gesture.

Android Pull or Swipe Down to Refresh Using SwipeRefreshLayout Example

Create an android studio project with package name com.swipetorefresh

Note: Make sure your project have dependency for android support library in build.gradle file.

Now add following code in respective files.

activity_main.xml

MainActivity.java

Save and run your project.

Screenshot

Android Pull or Swipe Down to Refresh Using SwipeRefreshLayout Example

Comment below if you have any difficulty or found anything incorrect in above android pull to refresh tutorial.

2 thoughts on “Android Pull or Swipe Down to Refresh Using SwipeRefreshLayout Example

  1. ultrasamad

    I love your tutorials because they are very simple to follow and straightforward.
    Thanks.

    Reply
    1. Admin Post author

      Thanks a lot, I will try my best to make them even more simpler and valuable.

      Reply

Leave a Reply

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