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

Quick Start Guide

Chris Banes edited this page Aug 10, 2012 · 6 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-PullToRefresh 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.

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 Customisation page for details of how to change the way the View looks/behaves, as well as the sample code.

Clone this wiki locally