SwipeRefreshLayout Android example #appenddata


SwipeRefreshLayout Android example

Sunday, March 30, 2014

Most of popular Android applications are having pull to refresh options, you might have used it. When pull down the screen the loading symbol appears and loading content become visible on top the application contents. Then the new contents will be fetched. This kind of pull to refresh has becoming out of date. Because it occupies 1/8 th part of screen and also a inconvinent way of processing.

Lets use the new kind of pull to refresh using SwipeRefreshLayout. you can see this pull to refresh in foursquare, google applications, hike. Its pretty awesome right.

This article will help you learn those kind of pull to refresh. It is very smooth and easy to implement. And it will support for the lower versions also (from v2.3). The below screen shot will recall the new kind of refresh.


UI part

Create an Android from your eclipse or Android studio.

In your activity layout add the SwipeRefreshLayout.

Note. It has only View inside the layout. Add the scrollView inside the SwipeRefresh layout to support pull to refresh. For ListView and GridView no need to add ScrollView inside SwipeRefreshLayout.

code part

Add the following lines in onCreate method of your Activity.

swipeLayout.setOnRefreshListener(this); sets Refresh listener for your layout.

Loading color schemes are adding using

To stop the loading progress swipeLayout.setRefreshing(false); .

Thats it. Run your appplicaton you also did the new pull to refresh.

Swipe to Refresh with ListView

Here I add an example of pull to refresh with listview. Then you will know how easy it is to integrate.

  1. Create a new Activity in your application, add the listview in your SwipeRefreshLayout.
  1. Declare and initialze variables for listview, adapter, String array for list items. Below codes will add the list items from array when you do pull to refresh.

Note. I have used appcompat library to support the Actionbar for lower versions. So My Activity extends ActionBarActivity. In updated ADT version of eclipse and studio, your application will be created with fragment concepts. So application is created with instant fragment concepts.

I guess you like this example. Try it yourself and get practiced.

Share this post

Leave a Reply

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