This repository was archived by the owner on Oct 15, 2018. It is now read-only.
-
-
Notifications
You must be signed in to change notification settings - Fork 4.7k
Quick Start Guide
Chris Banes edited this page Jun 28, 2012
·
6 revisions
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.
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" />
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.