A generic, customizable, open source Android ListView implementation that has 'Pull to Refresh' functionality.

Overview

Android 'Pull to Refresh' ListView library

Screenshot

Demo video: http://www.youtube.com/watch?v=VjmdELnm3GI

Project

A generic, customizable, open source Android ListView implementation that has 'Pull to Refresh' functionality. This ListView can be used as a replacement of the normal Android android.widget.ListView class.

/**
 * Users of this library should implement OnRefreshListener and call setOnRefreshListener(..)
 * to get notified on refresh events. The using class should call onRefreshComplete() when
 * refreshing is finished.
 * 
 * The using class can call setRefreshing() to set the state explicitly to refreshing. This 
 * is useful when you want to show the spinner and 'Refreshing' text when the
 * refresh was not triggered by 'Pull to Refresh', for example on start.
 * 
 * @author Erik Wallentinsen <dev+ptr at erikw.eu>
 */

Features

  • Drop-in replacement for the android.widget.ListView widget
  • Nice graphics (thanks to johannilsson - see credits)
  • Animations; bouncing animation and rotation animation (see video)
  • Easy to integrate in your Android project (see usage)
  • Works for any Android project targeting Android 1.6 (API level 4) and up
  • Highly customizable (using Android styles)

Info

Feel free to ask questions, report bugs and request features at dev at erikw dot eu or on the PullToRefresh-ListView github issue page. You can also hit me up on twitter if that's your thing.

Usage

Example project

Check out the example project in this repository for an implementation example. There is also moretechnical documentation available as javadoc in the library project code.

Layout

<!--
  The PullToRefresh-ListView replaces a standard ListView widget,
  and has all the features android.widget.ListView has.
-->
<eu.erikw.PullToRefreshListView
    android:id="@+id/pull_to_refresh_listview"
    android:layout_height="fill_parent"
    android:layout_width="fill_parent" />

Activity

// Set a listener to be invoked when the list should be refreshed.
PullToRefreshListView listView = (PullToRefreshListView) findViewById(R.id.pull_to_refresh_listview);
listView.setOnRefreshListener(new OnRefreshListener() {
    
    @Override
    public void onRefresh() {
        // Your code to refresh the list contents
        
        // ...
        
        // Make sure you call listView.onRefreshComplete()
        // when the loading is done. This can be done from here or any
        // other place, like on a broadcast receive from your loading
        // service or the onPostExecute of your AsyncTask.
        
        listView.onRefreshComplete();
    }
});

Style

To change the looks of the 'PullToRefresh' ListView, you can override the styles that are defined in the library project. Default, the looks are very basic (see screenshot above), with black text on a white background. You can change every aspect to your needs though, like the arrow image, text size, text color and background.

To do so, override the style attributes to your liking, like the following example:

<style name="ptr_text">
        
    <!-- Change the text style and color -->
    <item name="android:textStyle">bold|italic</item>
    <item name="android:textColor">#cccccc</item>
</style>

The various styles you can override are;

  • ptr_headerContainer
  • ptr_header
  • ptr_arrow
  • ptr_spinner
  • ptr_text

The default attributes can be found in the library project

Author

I’m a young, enthusiastic hacker from Amsterdam. I study computer science at the VU (Free University) and my work mostly involves Android programming. I do a lot of hacking in my spare time, resulting in many projects I want to share with the world.

Other projects

This project might not be the best library for you to use in your project, depending on your likes and needs. Consider using these great 'Pull to Refresh' libraries;

Credits

License

Copyright (c) 2012 - Erik Wallentinsen

Licensed under the Apache License, Version 2.0

Comments
  • Each time I pull to refresh my item in the list is clicked

    Each time I pull to refresh my item in the list is clicked

    Hi, I'm trying to use your project but actually I'm having a problem with the ClickEvent. Each time I do pull to refresh, the item pressed under my finger is called with the ClickEvent. I need to be able to do click the items but not when i'm refreshing it. I've been trying to control the list onItemClick event with the method isRefreshing() but before the State is updated, the Item Click Event is called and launch the detail associated to this item. Is there any way to control the pass of the event?

    Ps: when I declare the < eu.erikw.PullToRefreshListView.. I've added the android:clickable="false"/>.

    opened by lechon 7
  • OnItemClickListener & OnItemLongClickListener

    OnItemClickListener & OnItemLongClickListener

    Our ListView uses OnItemClickListener to switch to a detail view, and OnItemLongClickListener to reveal a button in the ListView item. I've switched to a PullToRefreshListView, and I find I still get these listeners firing when I'd expect the view to be consuming the touch events as part of the pull-to-refresh functionality. E.g. press and slowly move down, we start to reveal the 'pull to refresh' row at the top of the list, but we then get our OnItemLongClickListener called. Or pull down swiftly for 1/2 a row, again we see the 'pull to refresh' start to be displayed, but if you then release the touch we get the OnItemClickListener called.

    This feels wrong, I'd expect to have these Listeners called only if we're not doing any pull to refresh action. Is this how it's meant to work? Or is there some way I can configure it to behave the way we need?

    opened by jonathan-caryl 6
  •  java.lang.IllegalStateException

    java.lang.IllegalStateException

    Hi, I have the following error:

    java.lang.IllegalStateException: The content of the adapter has changed but ListView did not receive a notification. Make sure the content of your adapter is not modified from a background thread, but only from the UI thread. [in ListView(2131296374, class eu.erikw.PullToRefreshListView) with Adapter(class android.widget.HeaderViewListAdapter)]
    at android.widget.ListView.layoutChildren(ListView.java:1538)
    at android.widget.AbsListView.onTouchEvent(AbsListView.java:3702)
    at eu.erikw.PullToRefreshListView.onTouchEvent(PullToRefreshListView.java:350)
    at android.view.View.dispatchTouchEvent(View.java:7149)
    at android.view.ViewGroup.dispatchTransformedTouchEvent(ViewGroup.java:2173)
    at android.view.ViewGroup.dispatchTouchEvent(ViewGroup.java:1908)
    at android.view.ViewGroup.dispatchTransformedTouchEvent(ViewGroup.java:2179)
    at android.view.ViewGroup.dispatchTouchEvent(ViewGroup.java:1922)
    at android.view.ViewGroup.dispatchTransformedTouchEvent(ViewGroup.java:2179)
    at android.view.ViewGroup.dispatchTouchEvent(ViewGroup.java:1922)
    at android.view.ViewGroup.dispatchTransformedTouchEvent(ViewGroup.java:2179)
    at android.view.ViewGroup.dispatchTouchEvent(ViewGroup.java:1922)
    at android.view.ViewGroup.dispatchTransformedTouchEvent(ViewGroup.java:2179)
    at android.view.ViewGroup.dispatchTouchEvent(ViewGroup.java:1922)
    at android.view.ViewGroup.dispatchTransformedTouchEvent(ViewGroup.java:2179)
    at android.view.ViewGroup.dispatchTouchEvent(ViewGroup.java:1922)
    at com.android.internal.policy.impl.PhoneWindow$DecorView.superDispatchTouchEvent(PhoneWindow.java:2198)
    at com.android.internal.policy.impl.PhoneWindow.superDispatchTouchEvent(PhoneWindow.java:1574)
    at android.app.Activity.dispatchTouchEvent(Activity.java:2582)
    at com.android.internal.policy.impl.PhoneWindow$DecorView.dispatchTouchEvent(PhoneWindow.java:2147)
    at android.view.View.dispatchPointerEvent(View.java:7329)
    at android.view.ViewRootImpl.deliverPointerEvent(ViewRootImpl.java:3202)
    at android.view.ViewRootImpl.deliverInputEvent(ViewRootImpl.java:3144)
    at android.view.ViewRootImpl.doProcessInputEvents(ViewRootImpl.java:4183)
    at android.view.ViewRootImpl.enqueueInputEvent(ViewRootImpl.java:4162)
    at android.view.ViewRootImpl$WindowInputEventReceiver.onInputEvent(ViewRootImpl.java:4271)
    at android.view.InputEventReceiver.dispatchInputEvent(InputEventReceiver.java:171)
    at android.os.MessageQueue.nativePollOnce(Native Method)
    at android.os.MessageQueue.next(MessageQueue.java:125)
    at android.os.Looper.loop(Looper.java:124)
    at android.app.ActivityThread.main(ActivityThread.java:4941)
    at java.lang.reflect.Method.invokeNative(Native Method)
    at java.lang.reflect.Method.invoke(Method.java:511)
    at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:794)
    at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:561)
    at dalvik.system.NativeStart.main(Native Method)
    

    How can I solve that? I've just implemented the PullToRefreshView like in the sample code.

    Thanks

    opened by lauraoran 4
  • Adapter notifyDataSetChanged() is not working

    Adapter notifyDataSetChanged() is not working

    Thanks Eric for the great feature,

    I am having a problem with the list adapter it is not rendering the status of my linear layout after the onClickItem, while using the regular listView everything works just fine. Any suggestions to make the adapter work with your pull to refresh listView?? thanks again,

    Ali Tazami

    opened by alitazami 4
  • Adding layout animation does not work.

    Adding layout animation does not work.

    There seems to be an issue when adding a layout animation set to PullToRefreshListView via ListView's setLayoutAnimation. The animations being set do not work/run.

    I haven't tested this issue extensively, but I did have working code that used a ListView and would run a simple animation when an item was added to the list. When I swapped the ListView for a PullToRefreshListView, the animation would no longer run.

    opened by onyxmueller 4
  • onRefresh() is not called when I force it with setRefreshing()

    onRefresh() is not called when I force it with setRefreshing()

    I assume that it should be called but instead only the progress bar continues spinning. It seems you have a bug in the method

    public void setRefreshing(){ state = State.REFRESHING; scrollTo(0, 0); setUiRefreshing(); setHeaderPadding(0);

    }
    

    This method should be changed to:

    public void setRefreshing(){ setState(State.REFRESHING); scrollTo(0, 0); setUiRefreshing(); setHeaderPadding(0);

    }
    

    By setting the state this way the onRefreshListener.onRefresh(); is called.

    opened by alebrot 3
  • Development

    Development

    Hey there,

    Was looking for a good Android PullToRefresh library and yours best suited my needs. Just adding a last updated TextView underneath the main text to give the user an idea of when the data was last refreshed.

    Sean

    opened by seanoshea 3
  • listview items not completely displayed

    listview items not completely displayed

    I am using a listview that partially occupies the screen. Now when my items exceed the rows shown by default, the last item when finger scrolled down is only shown half and not the full cell row.

    opened by jom16antonio 3
  • NullPointerException when there is nothing to fetch.

    NullPointerException when there is nothing to fetch.

    How can you reproduce? When there is nothing to fetch, if you perform a click on the listview header, NPE occurs. I've solved it by adding "if(mOnItemClickListener != null && mState!=State.REFRESHING)". So the item click listener will not be consumed.

    The mOnItemClickListener (see point [1] below) is not null but it throws NPE because the arguments of the listener are null, because the event is not performed on any of the child items. In class: private class PTROnItemClickListener implements OnItemClickListener{

        @Override
        public void onItemClick(AdapterView<?> adapterView, View view, int position, long id) {
            mHasResetHeader = false;
    
            if(mOnItemClickListener != null && mState!=State.REFRESHING){  
                mOnItemClickListener.onItemClick(adapterView, view, position, id); ///      [1] 
            }
        }
    }
    

    Looking forward your feedback. Cheers!

    opened by NikolaDespotoski 2
  • Problem displaying elements after several

    Problem displaying elements after several "Pull-to-refresh" actions

    When you do "Pull-to-refresh" several times before the refreshing is finished, you are not able to scroll until the end of the list anymore, so there are some not-displayed or partially-displayed rows

    opened by hudomju 2
  • Create public methods for setting text in header.

    Create public methods for setting text in header.

    This is a feature request to create public methods for setting text in header. More specifically, public methods for changing 'Pull to refresh' and 'Release to refresh' text, to either something else or to nothing at all.

    With this being open-source, it was easy enough for me to hack in a solution, but I believe these are good public methods to have. See the PullToRefreshBase.java file of Chris Banes' project for something similar (https://github.com/chrisbanes/Android-PullToRefresh).

    Thanks!

    opened by onyxmueller 2
  • PTRListView below other layouts

    PTRListView below other layouts

    When we pull the list down the messages appear fine, the only problem is that the message comes above the other layout i have in the activity, then it disappears when the update is finished. It is like it does not know the position it should be within the listview. Maybe this library should only be used when the listview occupy the activity as a whole but not as a part of it!?

    opened by gustaveracosta 0
  • ptr_header.xml should include layout_width/layout_height or it will cause exception

    ptr_header.xml should include layout_width/layout_height or it will cause exception

    I have added it like here:

        <LinearLayout android:id="@+id/ptr_id_textwrapper" style="@style/ptr_textwrapper">
            <TextView android:id="@+id/ptr_id_text" style="@style/ptr_text"
                android:layout_height="wrap_content"
                android:layout_width="wrap_content" />
            <TextView android:id="@+id/ptr_id_last_updated" style="@style/ptr_last_updated"
                android:layout_width="wrap_content"
                android:layout_height="wrap_content" />
        </LinearLayout>
    </RelativeLayout>
    

    main.xml should add these too.

    opened by johnvuong20000 0
  • setOnItemClickListener has the wrong position.

    setOnItemClickListener has the wrong position.

    The position is wrong (may be -1) if item is clicked when pulling or refreshing.

        listView.setOnItemClickListener(new AdapterView.OnItemClickListener() {
            @Override
            public void onItemClick(AdapterView<?> adapterView, View view, int position, long l) {
    
            }
        });
    
    opened by ghost 3
  • fix some issue

    fix some issue

    fix the issue cause by build file.sample project is application ,not library. fix the issue cause by override style file.if override style file directly,it will cause some expection.like follows:

    java.lang.RuntimeException: Binary XML file line #8: You must supply a layout_width attribute.
    
    opened by mjkohoh 0
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
This project aims to provide a reusable pull to refresh widget for Android.

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 provi

Johan Berg 2.5k Jan 2, 2023
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
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
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
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
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
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
Bringing extended scrolling features to Android's native ListView and ExpandableListView.

About QuickScroll QuickScroll is a library aimed at creating similar scrolling experiences to the native Contacts app's People view. It has the same s

Andras Kindler 461 Nov 11, 2022
Android ListView with sticky headers

DEPRECATED HeaderListView is deprecated. No new development will be taking place. Quickstart Import the HeaderListView module in your Android Studio p

Applidium 314 Nov 10, 2022
Simple ListView based Android AccordionView

Android Accordion View Example git pull import to eclipse properties->android uncheck is library run as android application See main.xml. Screenshot L

Maciej Lopacinski 164 Nov 28, 2022
Android ListView that implements the QuickReturn UI pattern. Written from scratch with focus on performance.

QuickReturn Android ListView that implements the QuickReturn UI pattern. Written from scratch with focus on performance. Demo Usage In your build.grad

Felipe Lima 191 Nov 25, 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
[] A swipe menu for ListView.

SwipeMenuListView A swipe menu for ListView. Demo Usage Add dependency dependencies { compile 'com.baoyz.swipemenulistview:library:1.3.0' } Step 1

星一 3.5k Dec 16, 2022
An open source Android library that provides a floating group view at the top of the ExpandableListView

FloatingGroupExpandableListView FloatingGroupExpandableListView is a huge name an open source Android library that provides a floating group view (aka

Diego Lima 376 Nov 28, 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