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
To add the swipe to refresh widget to an existing app, add SwipeRefreshLayout as the parent of a single ListView or GridView . Remember that SwipeRefreshLayout only supports a single ListView or GridView child. You can also use the SwipeRefreshLayout widget with a ListFragment .
You should add the refresh action as a menu item, rather than as a button, by setting the attribute android:showAsAction=never . If you display the action as a button, users may assume that the refresh button action is different from the swipe-to-refresh action.
To refresh the ListView in Android, call notifyDataSetChanged() method on the Adapter that has been set with the ListView. Also note that the method notifyDataSetChanged() has to be called on UI thread.
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
).
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With