8

Does anyone has practice of using Pull to refresh list with Pinned section header? I use Android-PullToRefresh lib with my list and I want to add ability of showing pinned section header at the top of list. I used PinnedHeaderListView lib in another project for pinned section. But I can't combine these two libraries into one.

Is Android-PullToRefresh can show pinned section header? Perhaps any other Pull to refresh lib can do it?

dimetil
  • 3,851
  • 2
  • 29
  • 47
  • 1
    In my opinion you should use [ActionBar-PullToRefresh](https://github.com/chrisbanes/ActionBar-PullToRefresh) because Android-PullToRefresh has not been supported for 5 months. – mmBs Jun 24 '13 at 09:59
  • Great comment, I have to pay attention to the lib. But I'm not sure it supports pinned header. – dimetil Jun 24 '13 at 10:21
  • I'm trying to do the same thing. So far my only conclusion is that I have to implement one of the behaviour on top of one of the libraries.. because merging or using both will not work. – neteinstein Oct 17 '13 at 17:03
  • 1
    @NeTeInStEiN, you are mistaken, I've implemented this feature. you can check it in xMAP® Kit Finder app on Google Play (at search section). but I have no time to write full answer how I did it... I can send you some my classes. Do you interested in it still? – dimetil Oct 17 '13 at 19:27
  • Yes I would very much appreciate that, I'm still stuck on this. You can send to the email on my profile. Thanks really!!! – neteinstein Oct 18 '13 at 09:44
  • how you did it??? I also have to implement it, please give me some hints. Thanks, – Ahmad Raza Nov 29 '13 at 13:48

4 Answers4

9

It's possible to integrate the Actionbar-PullToRefresh library with the StickyListHeaders library, but you need to use a custom Delegate in order to get Actionbar-PullToRefresh to work correctly:

public class StickyListViewDelegate extends AbsListViewDelegate {
    @Override public boolean isReadyForPull(View view, final float x, final float y) {
    StickyListHeadersListView sticky = (StickyListHeadersListView) view;
    return super.isReadyForPull(sticky.getWrappedList(), x, y);
}

Integrated like so:

StickyListViewDelegate delegate = new StickyListViewDelegate();
ActionBarPullToRefresh.from(getActivity()).theseChildrenArePullable(mListView)
    .useViewDelegate(StickyListHeadersListView.class, delegate)
    .listener(this).setup(mPullToRefreshLayout);

The reason that the two libraries don't work together is because the StickyListHeadersListView class does not actually extend ListView (which is what the Actionbar-PullToRefresh library looks for when assigning a delegate by default).

Andrew Emery
  • 363
  • 3
  • 9
  • I tried your solution, but still its not working for me. Any other help can you provide? – AndyN Apr 01 '14 at 12:04
4

I did some research and I found 2 alternatives:

  1. StickyListHeaders. This library is contributed by Jake Wharton (reference) so it is promising and could be compatible with other libraries. You should try to use it.
  2. PinnedSectionListView - easy to use ListView with pinned sections for Android.

You can try combining these two libraries with ActionBar-PullToRefresh. I suppose you can implement the solution ;)

mmBs
  • 8,421
  • 6
  • 38
  • 46
2

You can use a combination of SwipeRefreshLayout of support-library and the PinnedHeaderListview.

In your XML file, use like following:

<android.support.v4.widget.SwipeRefreshLayout
        android:id="@+id/pinned_lisview_container"
        android:layout_width="match_parent"
        android:layout_height="match_parent" >

        <za.co.immedia.pinnedheaderlistview.PinnedHeaderListView
            android:id="@+id/event_items_lisview"
            android:layout_width="match_parent"
            android:layout_height="match_parent" >
        </za.co.immedia.pinnedheaderlistview.PinnedHeaderListView>
    </android.support.v4.widget.SwipeRefreshLayout>

And then in java code, just write codes for your PinnedHeaderListView as usual. Finally just put a Refresh Listener for your SwipeRefreshLayout like below:

pinned_lisview_container
                    .setOnRefreshListener(new OnRefreshListener() {

                        @Override
                        public void onRefresh() {
                        // do your refresh tasks here
                        }
                    });

You are done.

Md Tarik Mahmud
  • 331
  • 3
  • 8
0

SwipeRefreshLayout + any other suitable library that you would use can do the job. I would prefer PinnedSectionListView beacuse it uses Listview and it has it its pros in terms of UI/UX.

Fahad Ishaque
  • 1,916
  • 1
  • 17
  • 21