Skip to content
This repository has been archived by the owner on Oct 15, 2018. It is now read-only.

ListFragment

Chris Banes edited this page Dec 5, 2013 · 3 revisions

Using ActionBar-PullToRefresh with a ListFragment is slightly different, as ListFragment provides the whole content view itself. This means that we need to insert ourselves into the view hierachy. This is easiest shown with a code sample.

The only difference to the normal setup is that you create a PullToRefreshLayout manually, and need to use the insertLayoutInto(ViewGroup) method.

public class YourListFragment extends ListFragment {

    private PullToRefreshLayout mPullToRefreshLayout;

    @Override
    public void onViewCreated(View view, Bundle savedInstanceState) {
        super.onViewCreated(view,savedInstanceState);
        
        // This is the View which is created by ListFragment
        ViewGroup viewGroup = (ViewGroup) view;

        // We need to create a PullToRefreshLayout manually
        mPullToRefreshLayout = new PullToRefreshLayout(viewGroup.getContext());

        // We can now setup the PullToRefreshLayout
        ActionBarPullToRefresh.from(getActivity())
        
                // We need to insert the PullToRefreshLayout into the Fragment's ViewGroup
                .insertLayoutInto(viewGroup)
                
                // We need to mark the ListView and it's Empty View as pullable
                // This is because they are not dirent children of the ViewGroup
                .theseChildrenArePullable(getListView(), getListView().getEmptyView())
                
                // We can now complete the setup as desired
                .listener(...)
                .options(...)
                .setup(mPullToRefreshLayout);
    }
}
Clone this wiki locally