How to implement pull to refresh on a ListFragment
Asked Answered
A

3

16

I'm trying implement "pull to refresh" on a ListFragment but right now none of the drop in libraries seem to support it. There's no way to detect overscroll on the list fragment that I can see so I'm wondering if anyone has found a means to get this working?

--

Using Christian's tip I used the following for my onCreateView() method.

@Override
public View onCreateView (LayoutInflater inflater, ViewGroup container, Bundle savedInstanceState)
{
   PullToRefreshListView listView = new PullToRefreshListView(getActivity());
   mAdapter = new HomeTweetListAdapter(getActivity(), R.layout.tweet_list_item, tweets);
   listView.setAdapter(mAdapter);
   return listView;
}

Like Christian said you can only do this with a Fragment. Returning anything other than a ListView on a ListFragment errors out.

EDIT: To clarify I am using Johan's PullToRefresh library

Armenta answered 27/12, 2011 at 18:38 Comment(0)
T
10

I actually make it work using fragments (not ListFragment). So it is basically the same, just return the PullToRefreshListView from your onCreateView method and that's it. It should also work with ListFragment; remember that you must return a ListView from onCreateView if you use ListFragment (you can return whatever you want if you use just Fragment).

Telephoto answered 27/12, 2011 at 18:48 Comment(6)
So could he possible use my method?Mizzenmast
Yeah. Sure... I added another answer just because you did not take into account that he is working with Fragments, so things change a little bit there. Also, he seems to know that there are third-party libraries to do it... so he may already know about the one you suggested.Telephoto
I see where you're going with this. I've tried it but Eclipse doesn't like setting a list adapter to a plain old fragment. Is there a remedy for this?Armenta
Nevermind, figured it out. You set the adapter when creating the PullToRefreshListView. Thanks!Armenta
Updated the issue on github, github.com/johannilsson/android-pulltorefresh/issues/30Mayo
wow I spent three days on a probkem like this, totally missed returning list view requirement. thanks.Duramen
M
3

Here is a Component that Johan has created that adds a pull down to refresh feature..

Pull-To-Refresh

Main logic is implemented in PullToRefreshListView that extends ListView.

n your layouts you simply add it like this.

<com.markupartist.android.widget.PullToRefreshListView
android:id="@+id/android:list"
android:layout_height="fill_parent"
android:layout_width="fill_parent"
/>
Mizzenmast answered 27/12, 2011 at 18:41 Comment(1)
It is my understanding that Johan's code does not currently support listFragment's implementations. See hereArmenta
B
0

It is now fully documented how to use ActionBar-PullToRefresh together with ListFragment:

https://github.com/chrisbanes/ActionBar-PullToRefresh/wiki/ListFragment

Hope that helps!

Benignity answered 17/3, 2014 at 14:15 Comment(0)

© 2022 - 2024 — McMap. All rights reserved.