Skip to content
This repository has been archived by the owner on Jan 8, 2018. It is now read-only.

Quick Start Guide

Wonjun Kim edited this page Feb 28, 2014 · 47 revisions

Quick Start Guide

If you've never used an Android Library Project before, I would recommend reading this page: Managing Projects from Eclipse with ADT.

This is a very simple Quick Start Guide for modifying an existing app, to use this library.

Java version

Android Pull To Refresh needs to be compiled with a Java 1.6 compiler. If it's not you will see errors such as: run() must override a superclass method.

If you're using Eclipse it's pretty easy to change this:

Right-click on the library project and select "Properties -> Java Compiler", check "Enable project specific settings" and select 1.6 from "Compiler compliance settings" select box. Press OK and then "Clean" all of your projects.

Android SDK Version

Android Pull To Refresh can be built in Android SDK 16 as default. You can download SDK 16 from Android SDK Manager.

Reference the Pull To Refresh library from your project

Clone Pull To Refresh project into local from github

# git clone https://github.com/nhnopensource/android-pull-to-refresh.git
# git checkout v3.2.0

Download .classpath and .project, and copy those into the library folder as below.

# cp .classpath (cloned Pull To Refresh project path)/library
# cp .project (cloned Pull To Refresh project path)/library

Or if you are a maven user, run maven command as below,

# mvn eclipse:eclipse clean -Dandroid.sdk.path=(Android SDK Path)

Import the library project of Pull To Refresh. In ADT, select "File > Import > existing projects into Workspace" and click the "browse" button beside "root directory", and find the library folder of Pull To Refresh project. If you have found out, click the "Open" button.

Then you can see the Pull To Refresh library project. Click the "finish" button to import.

Next, reference the Pull To Refresh library project from your project by following the instruction.

If you did these steps successfully, then you can see the new property is added in project.properties as below.

android.library.reference.1=(Pull To Refresh library project path)

Additional steps for maven projects

In pom.xml, add the dependency below.

<dependencies>
<dependency>
    <groupId>com.navercorp.pulltorefresh</groupId>
    <artifactId>library</artifactId>
    <version>3.2.0</version>
    <type>apklib</type>
</dependency>
<dependencies>

Additional steps for gradle projects

In build.gradle, add the dependency below.

dependencies {
    compile 'com.navercorp.pulltorefresh:library:3.2.0@aar'
}

I'm a wrapper!

The first thing to know about this library is that it is a wrapper around the existing View classes. I try not to extend and change any standard Android View code (where possible). So if you use this library and want to get access to the internal ListView/GridView/etc then simply call getRefreshableView(). You can then call all of your usual methods such as setOnClickListener() etc.

Layout

The first thing to do is to modify your layout file to reference one of the PullToRefresh Views instead of an Android platform View (such as ListView), as so:

<!--
  The PullToRefreshListView replaces a standard ListView widget.
  The ID CAN NOT be @+id/android:list
-->
<com.handmark.pulltorefresh.library.PullToRefreshListView
    android:id="@+id/pull_to_refresh_listview"
    android:layout_height="fill_parent"
    android:layout_width="fill_parent" />

Activity

Now we can add the function so that the your application knows when a user has completed a 'PullToRefresh'.

// Set a listener to be invoked when the list should be refreshed.
PullToRefreshListView pullToRefreshView = (PullToRefreshListView) findViewById(R.id.pull_to_refresh_listview);
pullToRefreshView.setOnRefreshListener(new OnRefreshListener<ListView>() {
    @Override
    public void onRefresh(PullToRefreshBase<ListView> refreshView) {
        // Do work to refresh the list here.
        new GetDataTask().execute();
    }
});

private class GetDataTask extends AsyncTask<Void, Void, String[]> {
    ...
    @Override
    protected void onPostExecute(String[] result) {
        // Call onRefreshComplete when the list has been refreshed.
        pullToRefreshView.onRefreshComplete();
        super.onPostExecute(result);
    }
}

And that's it! I would now recommend having a look at the Customization page for details of how to change the way the View looks/behaves, as well as the sample code.