SwipeRefreshLayout in Android Fragment | An Introduction

Introduction to SwipeRefreshLayout

SwipeRefreshLayout was introduced in android.support.v4.widget.SwipeRefreshLayout library.
This feature displays when a user swipes down from the top and a circular loader appears. It will disappear when the content is refreshed.
The main use of SwipeRefreshLayout is to refresh the page or screen.

Real Time Example:
We can see so many applications like Gmail, G+, Facebook, Twitter uses this feature.

Interface & Methods:SwipeRefreshLayout.OnRefreshListener:
We implement this interface to notify when the user swipes down to refresh.onRefresh():
After implementing the interface, override this method. It is called when the user swipes down the view.

Example with code:
In this example, we are going to implement SwipeRefreshLayout using ListView in Android Fragment.
⦁ Create an Application SwipeRefreshLayoutFragmentExampleAndroid.
Requirements:
MainActivity.java, SwipeRefreshLayoutFragment.java, swipe_refresh_layout_fragment.xml, colors.xml, strings.xml.
Let’s do it one by one.

MainActivity.java:
Create this to add the fragment when the activity loads.
Add the code in onCreate(){…}

This was just a simple example of how to create SwipeRefreshlayout in Android fragment. We can also create it inside GridView or RecyclerView etc. This feature is mainly used to refresh the content most likely in News Feed applications. Some real time examples are discussed above.
It is introduced in Android support library. We can customize it to create great applications. It is quite important and popular in Android app development.