Coder Social home page Coder Social logo

actionbar-pulltorefresh's Introduction

ActionBar-PullToRefresh

ActionBar-PullToRefresh

ActionBar-PullToRefresh provides an easy way to add a modern version of the pull-to-refresh interaction to your application.

Please note that this is not an update to Android-PullToRefresh, this has been created from new. You should think of this as Android-PullToRefresh's younger, leaner cousin.

This is a Preview

Please note that this is currently in a preview state. This basically means that the API is not fixed and you should expect changes between releases.

Todo

As this is a preview also means that function is missing. See the Todo page for more info on what needs to be added.


Sample

Eventually the sample will be available to download on Google Play. As we're not stable yet you can find the APK here.


Supported Views

ActionBar-PullToRefresh has in-built support for:

  • AbsListView derivatives (ListView & GridView).
  • ScrollView

If the View you want to use is not listed above, you can easily add support by providing a Delegate. See the 'Delegates' section below for more info.


Usage

There are two ways to use this library, programmatically or declaratively.

Programmatically

You just need to create an instance of PullToRefreshAttacher, giving it the Activity and the View for which will scroll.

private PullToRefreshAttacher mPullToRefreshHelper;

@Override
public void onCreate(Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);
        
    // Get View for which the user will scroll…
    View scrollableView = findViewById(R.id.blah); 

    mPullToRefreshHelper = new PullToRefreshAttacher(this, scrollableView);
    mPullToRefreshHelper.setRefreshListener(this);
}

See the ListView sample for more info.

Declaratively

Here you just wrap your scrollable view in a PullToRefreshLayout in your layout XML:

<uk.co.senab.actionbarpulltorefresh.library.PullToRefreshLayout
    android:id="@+id/ptr_layout"
    xmlns:android="http://schemas.android.com/apk/res/android"
    xmlns:ptr="http://schemas.android.com/apk/res-auto"
    android:layout_width="fill_parent"
    android:layout_height="fill_parent"
    ptr:refreshScrollDistance="0.75">

    <ScrollView
        android:layout_width="fill_parent"
        android:layout_height="fill_parent"
        android:padding="8dp"
        android:scrollbarStyle="outsideInset">

        <TextView
            android:layout_width="fill_parent"
            android:layout_height="wrap_content"
            android:text="@string/filler_text" />

    </ScrollView>

</uk.co.senab.actionbarpulltorefresh.library.PullToRefreshLayout>

In you Activity/Fragment you then do the following to retrieve the generated PullToRefreshAttacher

// Retrieve PullToRefreshAttacher from PullToRefreshLayout
mPullToRefreshAttacher = PullToRefreshLayout.getAttacher(this, R.id.ptr_layout);

// Set Listener to know when a refresh should be started
mPullToRefreshAttacher.setRefreshListener(this);

See the ScrollView sample for more info.


Customisation

Delegates

TODO. See the GridView sample for more info for now.

HeaderTransformers

TODO. See the GridView sample for more info for now.


License

Copyright 2013 Chris Banes

Licensed under the Apache License, Version 2.0 (the "License");
you may not use this file except in compliance with the License.
You may obtain a copy of the License at

   http://www.apache.org/licenses/LICENSE-2.0

Unless required by applicable law or agreed to in writing, software
distributed under the License is distributed on an "AS IS" BASIS,
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
See the License for the specific language governing permissions and
limitations under the License.

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.