Skip to content Skip to sidebar Skip to footer

Actionbar-pulltorefresh With Listview And Fragment

I am trying to implement ActionBar-PullToRefresh in my application. The activity has a fragment in it and the fragment has a listview in it. The implementation of listview is with

Solution 1:

I believe the problem is that you are not using the ListView in your Fragment layout, but a default one from the framework, try this :

// setup the PullToRefreshLayout
    ActionBarPullToRefresh.from(getActivity())
            // We need to insert the PullToRefreshLayout into the Fragment's ViewGroup.insertLayoutInto(viewGroup)
            // Here we mark just the ListView and it's Empty View as pullable.theseChildrenArePullable(R.id. listview_news_list, android.R.id.empty)
            .listener(this)
            .setup(mPullToRefreshLayout);

If it's not working, you could also try by doing the following in your onCreateView method :

mPullToRefreshLayout = ((PullToRefreshLayout) view.findViewById(R.id.ptr_layout));

and then setup it like this in onActivityCreated or onViewCreated :

ActionBarPullToRefresh
    .from(getActivity())
    .allChildrenArePullable()
    .listener(this)
    .setup(this.mPullToRefreshLayout);

For the record, I am using PullToRefreshLayout inside a Fragment in my app and it's working just fine. Let me know if it works.

Solution 2:

You have to initialize the ActionBarPullToRefresh in the onCreate method of your Activity, not in onViewCreated of your Fragment. Initialize the library in the Activity, and pass it to the Fragment.

Post a Comment for "Actionbar-pulltorefresh With Listview And Fragment"