This tutorial contains information how to implement the swipe to refresh design pattern.

1. Supporting swipe to refresh

Android provides a widget that implements the swipe-to-refresh design pattern, which allows the user to trigger an update with a vertical swipe.

This is implemented by the SwipeRefreshLayout widget, which detects the vertical swipe, displays a distinctive progress bar, and triggers callback methods in your app. To support this, add the widget to your layout file as the parent of the relevant view, and implementing the refresh behavior that gets invoked when the user swipes.

To use the swipe to refresh widget ensure you have a dependency to the support library in your application Gradle build file.

dependencies {
    compile ''

        android:scrollbars="vertical" />

Even if you provide the swipe-to-refresh design pattern, you should still add a refresh button to your overflow menu in your toolbar to support the refresh for users unable to swipe.

In the SwipeRefreshLayout.OnRefreshListener method you implement the logic to update your view.

    new SwipeRefreshLayout.OnRefreshListener() {
        public void onRefresh() {

private void doYourUpdate() {
   // TODO implement a refresh
   setRefreshing(false); // Disables the refresh icon

If you also added a refresh action to your overflow menu in your toolbar ensure that you also show the refresh indicator.

public boolean onOptionsItemSelected(MenuItem item) {
    switch (item.getItemId()) {

            // signal SwipeRefreshLayout to start the progress indicator

            return true;
    return super.onOptionsItemSelected(item);

3. vogella training and consulting support

Copyright © 2012-2019 vogella GmbH. Free use of the software examples is granted under the terms of the Eclipse Public License 2.0. This tutorial is published under the Creative Commons Attribution-NonCommercial-ShareAlike 3.0 Germany license.