Swipe-to-Refresh

Pulling down a list to indicate a manual refresh is known as the Swipe-to-Refresh gesture. It's such a common feature that this functionality has been encapsulated in a single widget called SwipeRefreshLayout.

This recipe will show how to use the widget to add Swipe-to-Refresh functionality with a ListView. The following screenshot shows the refresh in action:

Swipe-to-Refresh

Getting ready

Create a new project in Android Studio and call it: SwipeToRefresh. Use the default Phone & Tablet options and select Empty Activity when prompted for the Activity Type.

How to do it...

First, we need to add the SwipeRefreshLayout widget and ListView to the activity ...

Get Android Application Development Cookbook - Second Edition now with the O’Reilly learning platform.

O’Reilly members experience books, live events, courses curated by job role, and more from O’Reilly and nearly 200 top publishers.