From the course: Android Development Essential Training: Manage Data with Kotlin

Unlock the full course today

Join today to access over 22,600 courses taught by industry experts or purchase this course individually.

Refresh data with a swipe gesture

Refresh data with a swipe gesture

From the course: Android Development Essential Training: Manage Data with Kotlin

Start my 1-month free trial

Refresh data with a swipe gesture

- [Instructor] Apps that get their data from the web sometimes need to refresh their data in reaction to a user gesture. The most common gesture for this is a top to bottom swipe and you can implement this in your own app with the component called SwipeRefreshLayout. I'm going to start this exercise in the MainFragment class. And I'm going to wrap my RecyclerView component inside an instance of this component. I'll start by typing the word swipe and then I'll select SwipeRefreshLayout. Now this is going to become the child element for the ConstraintLayout, so I'm going to set the width and the height to 0dp, then I'm going to cut and paste all the constraint properties from the RecyclerView to the SwipeRefreshLayout. I'll move the top to top of and the other three constraints. And then I'll close the element. And I'll cut and paste the nth tag to below the RecyclerView. RecyclerView is now a child of SwipeRefreshLayout, so instead of using 0dp, I'll use match_parent. I'll need to…

Contents