Skip to main content

How to use SwipeRefreshLayout? Example

Google just released a new version of Android Support Library with SwipeRefreshLayout[1]. It is pull to refresh layout based on Google Now, not Gmail. Before this release most of android developers use PullToRefresh library from Chris Banes (Special thanks to him for great libraries and android development tips) But with the recent release of Google, Chris drop his support to own library - PullToRefresh. [2] We have SwipeRefreshLayout now it is simple to use with a few line of codes.

Step One: Install

Update your Android Support Library in Android SDK manager and make sure you have version 19.1. Then right click on project and select "Android Tools->Add Support Library". After instaltion your project has brand new support library.

Step Two: Layout

You should add your scrool view or list view in to a "SwipeRefreshLayout"


Step Three: Code

In code we need a SwipeRefreshLibrary instance.

private SwipeRefreshLayout mSwipeRefreshLayout;

// onCreate()
mSwipeRefreshLayout = (SwipeRefreshLayout) findViewById(;

mSwipeRefreshLayout = (SwipeRefreshLayout) findViewById(;
// onRefresh() method when refresh finished.
  @Override public void onRefresh() {
      // Empty implementation

Now you are ready try this in your app. I just use it my new app, please try and do not hesitate to send your feedback :)


Popular posts from this blog

How to change position of MyLocationButton on new Map API v2 - 2

In my previuos post[1], i mention a workaround for changing buttons on Google Map which we use with google services. It is good to know they listen developers and make their products more development friendly. (I hope it goes like that way all the time and all the product lines of Google) Now we have a method for setting padding of map. It is add padding to useful area of map. We can see full screen map but with padding we can use prefered area of it. It is good for overlay action bar and other things on map view. [ 2] They write a blog and take a video about it. Read blog and watch video if you are using google map in your app :) [3] And finally, They add this method because of this issue. That means, if you find a bug or want extra feature from and api, write to google via this issue tracking system. [1] [2] [3] http://googlegeodeve

How to set alarm to show a notification at future date with AlarmManager?

Lets assume you want to do a job a future time or show a notification at a selected time. AlarmManager can help to send an intent in future time. First we need to select date, Lets create a date in 2050, Calendar calendar = Calendar. getInstance () ; calendar.set(Calendar. YEAR , 2050 ) ; Date date = calendar.getTime() ; For showing notification we need a service. public class AlarmReceiver extends Service { public AlarmReceiver() { } @Override public IBinder onBind (Intent intent) { } } Add service to Manifest.xml <service android :name= "com.kozaxinan.example.alarm.AlarmReceiver" android :enabled= "true" android :exported= "true" > </service> We will modify AlarmReceiver for sending notification. But first we need to register a alarm. AlarmManager alarmManager = (AlarmManager) getSystemService( ALARM_SERVICE ) ; Intent intent = new Intent( this, AlarmReceiver. class ) ; intent.putExtra( &q

Meteor Crush

You are the last hope of world Hit meteors and save everyone Accelerate satellites and crush meteors.  Clear endless danger waves. Tear meteors to pieces so planet and all living things can live. Smash meteorites and help world. Meteor Crush