Adding Swipe to Refresh

Introduction
In this tutorial, you will learn how to add the action to pull a view down to refresh it.

Creating the Layout
Add a SwipeRefreshLayout as a parent of the view you want to be able to refresh. The SwipeRefreshLayout must have only one child.  

 

Receiving the action input
In your activity, find the view of the SwipeRefresh Layout. final SwipeRefreshLayout refreshLayout = (SwipeRefreshLayout) findViewById(R.id.swiperefresh); Then, add a refresh listener triggering the methods required to refresh your view data. refreshLayout.setOnRefreshListener(         new SwipeRefreshLayout.OnRefreshListener {              @Override              public void onRefresh {                 loadData(station);              }          }  ); After you finish loading the data, insert the method to stop refreshing, so the progressbar will disapear and the view will be ready to be refreshed again. refreshLayout.setRefreshing(false);

Conclusion
Your activity now has a pull down to refresh action.

You now know how to add the action to pull a view down to refresh it.