Android RecyclerView Swipe Refresh Tutorial

In previous tutorial, I have implement a simple recyclerview tutorial to let you understand how its work. The recyclerview only display the static content is not a good practice. We should implement the refresh feature swipe up or down in the recyclerview to refresh the new content from the database or only visible 10 item per load. The swipe down refresh is very useful when come to you dont want to display all item at a time because it will cause the android app lag or some serious problem occur in the user device. So that you want to load and refresh only 10 items per refresh. This tutorial, I will provide the android recyclerview swipe refresh feature in this android project. So you will get use on it.

Creating a new Project

1. Open Android Studio IDE in your computer.
2. Create a new project and Edit the Application name to “SwipeRefreshRecyclerViewExample”.
(Optional) You can edit the company domain or select the suitable location for current project tutorial. Then click next button to proceed.
3. Select Minimum SDK (API 15:Android 4.0.3 (IceCreamSandwich). I choose the API 15 because many android devices currently are support more than API 15. Click Next button.
4. Choose “Empty Project” and Click Next button
5. Lastly, press finish button.

Add the new dependency

Include the recyclerview library in your androidmanifest file so you can use the recyclerview in your project later. After that click synchronise.

Create a item view layout

Right click the res>layout folder and create a new xml layout “item_view” for the each item view.

Create a progress view layout

Same as previous, create a layout but name it to “item_progress” after that follow the source code in the bottom.

Create a Modal class

Besides, add a new modal class “Item” and follow the sample source code below, I will add one string name item.

Create a new Adapter for Item

Create a new Adapter class “ItemAdapter”, if the item position is null then it will be show the progress bar.

Edit activity_main.xml layout

Go to activity_main.xml file and add the swiperefreshlayout such as the source code below.

Edit MainActivity.java class

Modify your mainactivity class and this class will handler the swipe feature in the recyclerview.

Run you Project

At last, you can try to run this project and test the refresh feature that just implement.

(Android RecyclerView Swipe Refresh)

Source Code

(Visited 1,571 times, 1 visits today)
Advertisements

Yong Loon Ng

Ng Yong Loon, better known as Kristofer is a software engineer and computer scientist who doubles up as an entrepreneur.

You may also like...

Leave a Reply

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