Android Pull To Refresh by using external Libraries

    In previous post, I have showed how to use SwipeRefreshLayout - an official widget of refreshing View (ListView, ScrollView,...). But there are a lot of external libraries which provide us more animations, UI design options and they're more poppular than the default ones.
In this tut, I'll show you how to make a refreshable layout by using ActionBar-PullToRefresh library (developed by Chris Banes).

1. Download 2 necessary libraries

These libraries written in Android Studio project format so we must config them to use in Eclipse. For convenient, I have fixed them already. You can download at:
- SmoothProgressBar: Link
- ActionBar-PullToRefreshLink 

2. Import these project to eclipse and make reference

After import them, with SmoothProgressBar:
- Right Click  project  name and goto “Properties”
- Choose Android tab, under Library area check "Is Library" check box.
- Remember choosing Project Build Target 5.0 or higher.
With ActionBar-PullToRefresh: similar as bove, after that, make reference with smoothprogressbar project by click Add button:

3. Start a new Android Project to using them

Min-sdk I used is 14.
Before coding, remember to make this project reference to 2 libraries (like above picture). In this project, I will parse xml from an url and getting data to views after an AsyncTask done.
Declaring an activity layout (activity_pull_to_refresh.xml):

Make a customize AsyncTask to get data from Internet (Weather data):
In our activity, we must:
- config PullToRefreshLayout properties (in onCreate() method of Activity, after locate views).
- Implement pull to refresh library OnRefreshListener and override onRefreshStarted() method.
- set setRefreshComplete() after receive response data successful.

Full code:
Make some strings in resource (strings.xml):
Open AndroidManifest.xml and add Internet permission:
Some app screens:
pic name pic name pic name
- ActionBar-PullToRefresh official in Github:
- SmoothProgressBar official in Github:
- You can see how to fix 2 libraries to use in Eclipse at this tutorial.
- Libraries Author Homepage:
- My SwipeRefreshLayout tutorial post: HERE!

(Sorry for having ads)


Previous post
« Prev Post
Next post
Next Post »