This project aims to provide a reusable pull to refresh widget for Android.

Overview

Pull To Refresh for Android

Note This library is deprecated, a swipe refresh layout is available in the v4 support library.


This project aims to provide a reusable pull to refresh widget for Android.

Screenshot

Repository at https://github.com/johannilsson/android-pulltorefresh.

Usage

Layout

<!--
  The PullToRefreshListView replaces a standard ListView widget.
-->
<com.markupartist.android.widget.PullToRefreshListView
    android:id="@+id/android:list"
    android:layout_height="fill_parent"
    android:layout_width="fill_parent"
    />

Activity

// Set a listener to be invoked when the list should be refreshed.
((PullToRefreshListView) getListView()).setOnRefreshListener(new OnRefreshListener() {
    @Override
    public void onRefresh() {
        // Do work to refresh the list here.
        new GetDataTask().execute();
    }
});

private class GetDataTask extends AsyncTask<Void, Void, String[]> {
    ...
    @Override
    protected void onPostExecute(String[] result) {
        mListItems.addFirst("Added after refresh...");
        // Call onRefreshComplete when the list has been refreshed.
        ((PullToRefreshListView) getListView()).onRefreshComplete();
        super.onPostExecute(result);
    }
}

Last Updated

It's possible to add a last updated time using the method setLastUpdated and onRefreshComplete. The text provided to these methods will be set below the Release to refresh text. Note that the time representation is not validated replaces the previous text, which means that it's possible and recommended to add a text similar to "Last Update: 15:23". This might be changed in future versions.

1.5 Support

To use the widget on 1.5 the necessary drawables needs to be copied to that projects drawable folder. The drawables needed by the widget can be found in the drawable-hdpi folder in the library project.

Contributors

Are you using this widget?

If you are using this widget please feel free to add your app to the wiki.

License

Copyright (c) 2011 Johan Nilsson

Licensed under the Apache License, Version 2.0

Comments
  • This makes the pointless tap-to-refresh button go away after refresh.

    This makes the pointless tap-to-refresh button go away after refresh.

    This library is one of the best pull-to-refresh libraries, it is not perfect, but it is close. Lets develop it to perfection. It is not as fast as the Twitter client for Android, how can we speed it up, any ideas?? Please take this commit, I don't see any point in the tap-to-refresh button.

    opened by h-unterp 16
  • Cannot Cast From ListView to PullToRefreshListView

    Cannot Cast From ListView to PullToRefreshListView

    I pulled the exact same sample code that you have and it seems as though using the following does not work...

    ((PullToRefreshListView) getListView()).setOnRefreshListener(new OnRefreshListener() { @Override public void onRefresh() { // Do work to refresh the list here. new GetDataTask().execute(); } });

    Is this a known issue already? Using findViewById() seems to be the only workaround.

    opened by alexfu 10
  • Listview on ItemClick gives wrong position

    Listview on ItemClick gives wrong position

    When i click on item position it gives wrong position.for example i am clicking on position no 2 the it give the value of position 3.let me know how can i resolve this issue please

    opened by lakkad-amish 8
  • Crash on 10.1 Tablet

    Crash on 10.1 Tablet

    10-31 12:23:31.100: E/AndroidRuntime(2626): at android.view.ViewGroup.dispatchTouchEvent(ViewGroup.java:1333) 10-31 12:23:31.100: E/AndroidRuntime(2626): at android.view.ViewGroup.dispatchTransformedTouchEvent(ViewGroup.java:1560) 10-31 12:23:31.100: E/AndroidRuntime(2626): at android.view.ViewGroup.dispatchTouchEvent(ViewGroup.java:1333) 10-31 12:23:31.100: E/AndroidRuntime(2626): at android.view.ViewGroup.dispatchTransformedTouchEvent(ViewGroup.java:1560) 10-31 12:23:31.100: E/AndroidRuntime(2626): at android.view.ViewGroup.dispatchTouchEvent(ViewGroup.java:1333) 10-31 12:23:31.100: E/AndroidRuntime(2626): at android.view.ViewGroup.dispatchTransformedTouchEvent(ViewGroup.java:1560) 10-31 12:23:31.100: E/AndroidRuntime(2626): at android.view.ViewGroup.dispatchTouchEvent(ViewGroup.java:1333) 10-31 12:23:31.100: E/AndroidRuntime(2626): at com.android.internal.policy.impl.PhoneWindow$DecorView.superDispatchTouchEvent(PhoneWindow.java:1863) 10-31 12:23:31.100: E/AndroidRuntime(2626): at com.android.internal.policy.impl.PhoneWindow.superDispatchTouchEvent(PhoneWindow.java:1287) 10-31 12:23:31.100: E/AndroidRuntime(2626): at android.app.Activity.dispatchTouchEvent(Activity.java:2309) 10-31 12:23:31.100: E/AndroidRuntime(2626): at com.android.internal.policy.impl.PhoneWindow$DecorView.dispatchTouchEvent(PhoneWindow.java:1836) 10-31 12:23:31.100: E/AndroidRuntime(2626): at android.view.View.dispatchPointerEvent(View.java:4689) 10-31 12:23:31.100: E/AndroidRuntime(2626): at android.view.ViewRoot.deliverPointerEvent(ViewRoot.java:2365) 10-31 12:23:31.100: E/AndroidRuntime(2626): at android.view.ViewRoot.handleMessage(ViewRoot.java:2034) 10-31 12:23:31.100: E/AndroidRuntime(2626): at android.os.Handler.dispatchMessage(Handler.java:99) 10-31 12:23:31.100: E/AndroidRuntime(2626): at android.os.Looper.loop(Looper.java:132) 10-31 12:23:31.100: E/AndroidRuntime(2626): at android.app.ActivityThread.main(ActivityThread.java:4028) 10-31 12:23:31.100: E/AndroidRuntime(2626): at java.lang.reflect.Method.invokeNative(Native Method) 10-31 12:23:31.100: E/AndroidRuntime(2626): at java.lang.reflect.Method.invoke(Method.java:491) 10-31 12:23:31.100: E/AndroidRuntime(2626): at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:844) 10-31 12:23:31.100: E/AndroidRuntime(2626): at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:602) 10-31 12:23:31.100: E/AndroidRuntime(2626): at dalvik.system.NativeStart.main(Native Method) 10-31 12:23:31.100: W/ActivityManager(288): Force finishing activity com.shopamani.shpmn/.activities.TumKampanyalarActivity

    opened by barisatbas 5
  • Crash at startup

    Crash at startup

    I have implemented PullToRefreshView in my project but sometimes at startup the app crashes with the following log:

    10-24 13:16:29.067: E/AndroidRuntime(3667): FATAL EXCEPTION: main
    10-24 13:16:29.067: E/AndroidRuntime(3667): java.lang.IndexOutOfBoundsException: Invalid index 0, size is 0
    10-24 13:16:29.067: E/AndroidRuntime(3667):     at java.util.ArrayList.throwIndexOutOfBoundsException(ArrayList.java:257)
    10-24 13:16:29.067: E/AndroidRuntime(3667):     at java.util.ArrayList.get(ArrayList.java:311)
    10-24 13:16:29.067: E/AndroidRuntime(3667):     at android.widget.HeaderViewListAdapter.isEnabled(HeaderViewListAdapter.java:164)
    10-24 13:16:29.067: E/AndroidRuntime(3667):     at android.widget.ListView.dispatchDraw(ListView.java:3061)
    10-24 13:16:29.067: E/AndroidRuntime(3667):     at android.view.View.draw(View.java:7003)
    10-24 13:16:29.067: E/AndroidRuntime(3667):     at android.widget.AbsListView.draw(AbsListView.java:2641)
    10-24 13:16:29.067: E/AndroidRuntime(3667):     at android.view.ViewGroup.drawChild(ViewGroup.java:1646)
    10-24 13:16:29.067: E/AndroidRuntime(3667):     at android.view.ViewGroup.dispatchDraw(ViewGroup.java:1373)
    10-24 13:16:29.067: E/AndroidRuntime(3667):     at android.view.View.draw(View.java:6900)
    10-24 13:16:29.067: E/AndroidRuntime(3667):     at android.view.ViewGroup.drawChild(ViewGroup.java:1646)
    10-24 13:16:29.067: E/AndroidRuntime(3667):     at android.view.ViewGroup.dispatchDraw(ViewGroup.java:1373)
    10-24 13:16:29.067: E/AndroidRuntime(3667):     at android.view.View.draw(View.java:6900)
    10-24 13:16:29.067: E/AndroidRuntime(3667):     at android.widget.FrameLayout.draw(FrameLayout.java:357)
    10-24 13:16:29.067: E/AndroidRuntime(3667):     at android.view.ViewGroup.drawChild(ViewGroup.java:1646)
    10-24 13:16:29.067: E/AndroidRuntime(3667):     at android.view.ViewGroup.dispatchDraw(ViewGroup.java:1373)
    10-24 13:16:29.067: E/AndroidRuntime(3667):     at android.view.View.draw(View.java:6900)
    10-24 13:16:29.067: E/AndroidRuntime(3667):     at android.widget.FrameLayout.draw(FrameLayout.java:357)
    10-24 13:16:29.067: E/AndroidRuntime(3667):     at com.android.internal.policy.impl.PhoneWindow$DecorView.draw(PhoneWindow.java:1908)
    10-24 13:16:29.067: E/AndroidRuntime(3667):     at android.view.ViewRoot.draw(ViewRoot.java:1527)
    10-24 13:16:29.067: E/AndroidRuntime(3667):     at android.view.ViewRoot.performTraversals(ViewRoot.java:1263)
    10-24 13:16:29.067: E/AndroidRuntime(3667):     at android.view.ViewRoot.handleMessage(ViewRoot.java:1865)
    10-24 13:16:29.067: E/AndroidRuntime(3667):     at android.os.Handler.dispatchMessage(Handler.java:99)
    10-24 13:16:29.067: E/AndroidRuntime(3667):     at android.os.Looper.loop(Looper.java:130)
    10-24 13:16:29.067: E/AndroidRuntime(3667):     at android.app.ActivityThread.main(ActivityThread.java:3835)
    10-24 13:16:29.067: E/AndroidRuntime(3667):     at java.lang.reflect.Method.invokeNative(Native Method)
    10-24 13:16:29.067: E/AndroidRuntime(3667):     at java.lang.reflect.Method.invoke(Method.java:507)
    10-24 13:16:29.067: E/AndroidRuntime(3667):     at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:847)
    10-24 13:16:29.067: E/AndroidRuntime(3667):     at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:605)
    10-24 13:16:29.067: E/AndroidRuntime(3667):     at dalvik.system.NativeStart.main(Native Method)
    

    Is there someting I am doing wrong? I have added the widget in my xml and set adapter in onCreate...

    opened by dmarcato 5
  • Bouncing when flinging upwards to the top.

    Bouncing when flinging upwards to the top.

    If you are somewhere in the list, then fling up to the top, the list bounces after a short delay.

    Not sure why this is, and I haven't been able to fix it. It seems to happen right before the scroll state is set to idle. Any suggestions?

    opened by timbaloney 5
  • Works only with linked list

    Works only with linked list

    Hi i am trying to implement in my project in which i am using custom list view with BaseAdapter but its not working properly its showing tap to refresh text always and scroll bar is not working for list

    opened by saritagandhi 4
  • Tried to build with Eclipse, getting errors?

    Tried to build with Eclipse, getting errors?

    Description Resource Path Location Type The method onClick(View) of type PullToRefreshListView.OnClickRefreshListener must override a superclass method PullToRefreshListView.java /pulltorefresh/src/com/markupartist/android/widget line 388 Java Problem The method onScroll(AbsListView, int, int, int) of type PullToRefreshListView must override a superclass method PullToRefreshListView.java /pulltorefresh/src/com/markupartist/android/widget line 277 Java Problem The method onScrollStateChanged(AbsListView, int) of type PullToRefreshListView must override a superclass method PullToRefreshListView.java /pulltorefresh/src/com/markupartist/android/widget line 321 Java Problem

    opened by efontana 4
  • PullToRefreshListView Coming Up As Null On 3.1 Honeycomb Devices

    PullToRefreshListView Coming Up As Null On 3.1 Honeycomb Devices

    Hey there,

    I'm using sections_list = (PullToRefreshListView)findViewById(android.R.id.list);

    which is working perfectly on all devices I've tested it on with 2.1, 2.2, 2.3.x but I've just noticed that on devices running 3.x when trying to find the same id its returning null which is then crashing the app as there is no list to set the adapter too.

    Is there another way to find this element? I've tried renaming it differently and it still returns null.

    The XML looks like this for the element (and as I said it works fine on the other versions of android)

    com.evolusent.lifestyler2.pulltorefresh.PullToRefreshListView android:id="@+id/android:list" android:layout_width="fill_parent" android:layout_height="fill_parent" android:layout_margin="0px" android:layout_below="@id/contents_header" android:scrollbars="none" />

    opened by kittcoldfire 4
  • IllegalArgumentException: historyPos out of range

    IllegalArgumentException: historyPos out of range

    On android 3.2 - both Galaxy 10.1 and Acer A100, I see this behaviour when pulling to refresh:

    E/AndroidRuntime(14918): FATAL EXCEPTION: main
    E/AndroidRuntime(14918): java.lang.IllegalArgumentException: historyPos out of range
    E/AndroidRuntime(14918):    at android.view.MotionEvent.nativeGetAxisValue(Native Method)
    E/AndroidRuntime(14918):    at android.view.MotionEvent.getHistoricalY(MotionEvent.java:1828)
    E/AndroidRuntime(14918):    at com.markupartist.android.widget.PullToRefreshListView.applyHeaderPadding(PullToRefreshListView.java:224)
    E/AndroidRuntime(14918):    at com.markupartist.android.widget.PullToRefreshListView.onTouchEvent(PullToRefreshListView.java:195)
    E/AndroidRuntime(14918):    at android.view.View.dispatchTouchEvent(View.java:4609)
    E/AndroidRuntime(14918):    at android.view.ViewGroup.dispatchTransformedTouchEvent(ViewGroup.java:1554)
    E/AndroidRuntime(14918):    at android.view.ViewGroup.dispatchTouchEvent(ViewGroup.java:1320)
    E/AndroidRuntime(14918):    at android.view.ViewGroup.dispatchTransformedTouchEvent(ViewGroup.java:1560)
    E/AndroidRuntime(14918):    at android.view.ViewGroup.dispatchTouchEvent(ViewGroup.java:1333)
    E/AndroidRuntime(14918):    at android.view.ViewGroup.dispatchTransformedTouchEvent(ViewGroup.java:1560)
    E/AndroidRuntime(14918):    at android.view.ViewGroup.dispatchTouchEvent(ViewGroup.java:1333)
    E/AndroidRuntime(14918):    at android.view.ViewGroup.dispatchTransformedTouchEvent(ViewGroup.java:1560)
    E/AndroidRuntime(14918):    at android.view.ViewGroup.dispatchTouchEvent(ViewGroup.java:1333)
    E/AndroidRuntime(14918):    at android.view.ViewGroup.dispatchTransformedTouchEvent(ViewGroup.java:1560)
    E/AndroidRuntime(14918):    at android.view.ViewGroup.dispatchTouchEvent(ViewGroup.java:1333)
    E/AndroidRuntime(14918):    at com.android.internal.policy.impl.PhoneWindow$DecorView.superDispatchTouchEvent(PhoneWindow.java:1732)
    E/AndroidRuntime(14918):    at com.android.internal.policy.impl.PhoneWindow.superDispatchTouchEvent(PhoneWindow.java:1267)
    E/AndroidRuntime(14918):    at android.app.Activity.dispatchTouchEvent(Activity.java:2315)
    E/AndroidRuntime(14918):    at com.android.internal.policy.impl.PhoneWindow$DecorView.dispatchTouchEvent(PhoneWindow.java:1705)
    E/AndroidRuntime(14918):    at android.view.View.dispatchPointerEvent(View.java:4677)
    E/AndroidRuntime(14918):    at android.view.ViewRoot.deliverPointerEvent(ViewRoot.java:2392)
    E/AndroidRuntime(14918):    at android.view.ViewRoot.handleMessage(ViewRoot.java:2054)
    E/AndroidRuntime(14918):    at android.os.Handler.dispatchMessage(Handler.java:99)
    E/AndroidRuntime(14918):    at android.os.Looper.loop(Looper.java:132)
    E/AndroidRuntime(14918):    at android.app.ActivityThread.main(ActivityThread.java:4123)
    E/AndroidRuntime(14918):    at java.lang.reflect.Method.invokeNative(Native Method)
    E/AndroidRuntime(14918):    at java.lang.reflect.Method.invoke(Method.java:491)
    E/AndroidRuntime(14918):    at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:841)
    E/AndroidRuntime(14918):    at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:599)
    E/AndroidRuntime(14918):    at dalvik.system.NativeStart.main(Native Method)
    
    opened by quiffman 4
  • Can we make pulltorefresh from bottom instead top?

    Can we make pulltorefresh from bottom instead top?

    It sounds weird, but I want to pull up to refresh. It means after scrolling to bottom of Listview, now I will pull up and release to perform pulltorefresh.

    Can we do it?

    P/S: it's not an issue but just a suggestion.

    Thanks. anticafe

    opened by anticafe 4
  • Possible to add

    Possible to add "Load More" button at footer view to loat more data?

    Possible to add "Load More" button at footer view to loat more data?

    Since my data store in server side and will present page by page. Its will be great if there has plan to add "Load More" function in pulltorefresh list.

    Anyway, this is a good widget and thanks for you guys excellent job.

    opened by foxty 0
  • Fast scrolling jump to first visible row

    Fast scrolling jump to first visible row

    I have a problem while fast scrolling. and reach to the last visible items it some time jumped to first visible row and some time not, i don't know the reason. any help guys?

    opened by AhmadHegazy 0
  • Boundary instability issue

    Boundary instability issue

    Hello, I'm trying to implement my own listview extending your lib. I found a problem while testing. When you drag very slowly near/across boundary at first time, the view becomes unstable and reporting warnings on loading message textview. I found out that you omitted a very tiny condition judging in your codes. It can be improved by modifying the onScroll() method in line 292 to 293, putting one more condition if (mRefreshView.getBottom() < mRefreshViewHeight + 20 && mRefreshView.getTop() != 0 && mRefreshState != PULL_TO_REFRESH) instead of if (mRefreshView.getBottom() < mRefreshViewHeight + 20 && mRefreshState != PULL_TO_REFRESH)

    opened by martin-oy 0
Owner
Johan Berg
✨ 🐶 ✨ 🚍 ✨ 🍷 ✨ 📖 ✨
Johan Berg
A generic, customizable, open source Android ListView implementation that has 'Pull to Refresh' functionality.

Android 'Pull to Refresh' ListView library Demo video: http://www.youtube.com/watch?v=VjmdELnm3GI Project A generic, customizable, open source Android

Erik Wallentinsen 639 Nov 17, 2022
android custom listview,with interaction pattern load more and pull to refresh to load data dinamically

The first thing that i have to say is render thanks to johannilsson because all the part of pull to refresh listview is based in the code of his repos

Fabian Leon 447 Nov 15, 2022
Phoenix Pull-to-Refresh

Phoenix Pull-to-Refresh This project aims to provide a simple and customizable pull to refresh implementation. Made in [Yalantis] (https://yalantis.co

Yalantis 4k Dec 30, 2022
An Android custom ListView and ScrollView with pull to zoom-in.

PullZoomView An Android custom ListView and ScrollView with pull to zoom-in. Features Set ZoomView enable Add HeaderView Custom ZoomView Parallax or N

Frank-Zhu 2.3k Dec 26, 2022
HorizontalListView is an Android ListView widget which scrolls in a horizontal manner (in contrast with the SDK-provided ListView which scrolls vertically).

HorizontalListView HorizontalListView is an Android ListView widget which scrolls in a horizontal manner (in contrast with the SDK-provided ListView w

MeetMe 722 Nov 10, 2022
AssignmentListView is an Android ListView widget which calculate image loading times.

AssignmentListView is an Android ListView widget which calculate image loading times.

null 5 Sep 9, 2022
An easy to use Drag & Drop List for Android. Direct replacement of the android ListView.

DragNDropListView DragNDropListView is a direct replacement for the stock Android ListView. If you know how to use ListView, you already know how to u

null 187 Dec 22, 2022
Android library to observe scroll events on scrollable views.

Android-ObservableScrollView Android library to observe scroll events on scrollable views. It's easy to interact with the Toolbar introduced in Androi

Soichiro Kashima 9.6k Dec 30, 2022
An android library for section headers that stick to the top

StickyListHeaders StickyListHeaders is an Android library that makes it easy to integrate section headers in your ListView. These section headers stic

Emil Sjölander 5.5k Jan 5, 2023
Easy to use ListView with pinned sections for Android.

Easy to use ListView with pinned sections for Android 2.1 and higher. Pinned section is a header view which sticks to the top of the list until at lea

Sergej Shafarenka 2.6k Dec 21, 2022
Lazy load of images in Android

LazyList A simple library to display images in Android ListView. Images are being downloaded asynchronously in the background. Images are being cached

Fedor Vlasov 1.2k Nov 15, 2022
Android library to achieve in an easy way, the behaviour of the home page in the Expedia app, with a pair of auto-scroll circular parallax ListViews.

ListBuddies This library is not maintained anymore and there will be no further releases Android library of a pair of auto-scroll circular parallax Li

JPARDOGO 970 Dec 29, 2022
Horizontal list view for Android which allows variable items widths

Deprecated This widget is now deprecated and it won't be updated anymore. Use RecyclerView instead Horizontal Variable ListView Horizontal ListView fo

Alessandro Crugnola 862 Nov 15, 2022
A small android library for tagging views inside a ScrollView as "sticky" making them stick to the top of the scroll container until a new sticky view comes and takes it's place

StickyScrollViewItems StickyScrollViewItems is a ScrollView subclass that allowed you to mark items inside the ScrollView as sticky. The items marked

Emil Sjölander 1k Jan 7, 2023
A ListView with pinned section headers for Android

PinnedHeaderListView This library provides a sectioned ListView with pinned headers. It looks and feels much like the default contacts app does on And

James Smith 665 Nov 29, 2022
This is a very simple library for Android that allows you to stick an header to a scrollable view and easily apply animation to it

StikkyHeader This is a very simple library for Android that allows you to stick an header to a ListView and easily apply animation to it Usage To use

Carlo Marinangeli 847 Dec 30, 2022
Parallax ScrollView and ListView for Android

Parallax Scrolls Parallax ListView and ScrollView for Android This project includes ScrollView with one or more parallaxed views ListView with paralla

Nir Hartmann 851 Dec 3, 2022
Android library to display a ListView whose cells are not rigid but flabby and react to ListView scroll.

FlabbyListView This library is not maintained anymore and there will be no further releases Android library to display a ListView which cells are not

JPARDOGO 762 Nov 23, 2022
Awesome Listview filter functionality in Android.

About Awesome Listview filter functionality in Android. See it in Action: https://www.youtube.com/watch?v=RO54U1ES5CA Listview with beautiful transpar

Bhavya  Mehta 446 Nov 20, 2022