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

QuickStart ABS

Chris Banes edited this page Mar 28, 2014 · 4 revisions

This version of the quick start is for when you are targetting a minSdkVersion of 7 and using ActionBarSherlock

Adding Library as a Dependency

The easiest way to add ActionBar-PullToRefresh to your project is via Gradle, you just need to add the following dependency to your build.gradle:

dependencies {  
    repositories {
        mavenCentral()
    }
    compile 'com.github.chrisbanes.actionbarpulltorefresh:extra-abs:+'
}

This means that you will always use the latest version available.

Integrate

The next step is now to integrate the library into your code, and connect the pull-to-refresh gesture to your Views.

The first thing you need to do is wrap your refreshable view in a PullToRefreshLayout:

<uk.co.senab.actionbarpulltorefresh.extras.actionbarsherlock.PullToRefreshLayout
    xmlns:android="http://schemas.android.com/apk/res/android"
    android:id="@+id/ptr_layout"
    android:layout_width="match_parent"
    android:layout_height="match_parent">
    
    <!-- Your content, here we're using a ScrollView -->

    <ScrollView
        android:layout_width="match_parent"
        android:layout_height="match_parent">
            
    </ScrollView>

</uk.co.senab.actionbarpulltorefresh.extras.actionbarsherlock.PullToRefreshLayout>

Then in your Activity or Fragment, use the ActionBarPullToRefresh class to setup the PullToRefreshLayout.

import uk.co.senab.actionbarpulltorefresh.extras.actionbarsherlock.PullToRefreshAttacher;

// ...

private PullToRefreshLayout mPullToRefreshLayout;

@Override
public void onCreate(Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);
        
    // Now find the PullToRefreshLayout to setup
    mPullToRefreshLayout = (PullToRefreshLayout) findViewById(R.id.ptr_layout);
    
    // Now setup the PullToRefreshLayout
    ActionBarPullToRefresh.from(this)
            // Mark All Children as pullable
            .allChildrenArePullable()
            // Set a OnRefreshListener
            .listener(...)
            // Finally commit the setup to our PullToRefreshLayout
            .setup(mPullToRefreshLayout);
}

Options

The above will get you the default experience but you may want to change some things. There a number of configuration options available and they are set via a Options instance.

ActionBarPullToRefresh.from(this)
        .options(Options.create()
                // Here we make the refresh scroll distance to 75% of the refreshable view's height
                .scrollDistance(.75f)
                // Here we define a custom header layout which will be inflated and used
                .headerLayout(R.layout.customised_header)
                // Here we define a custom header transformer which will alter the header
                // based on the current pull-to-refresh state
                .headerTransformer(new CustomisedHeaderTransformer())
                .build())
                
        // Now carry on with the rest of the setup
        .allChildrenArePullable()
        .listener(...)
        .setup(...);

There are a number of configuration values in the Options class. See the Customisation page for more details.

Clone this wiki locally