listfragment上的pulltorefresh

时间:2014-03-15 13:32:07

标签: android android-listfragment pull-to-refresh

我正在使用Chrisbanes pullToRfresh进行listfragment。我现在被困住了。这是我的onCreateView函数。

@Override
public View onCreateView(LayoutInflater inflater, ViewGroup container,
        Bundle savedInstanceState) {
    this.context = getActivity();
    Log.i("m4k", "Inside onCreateView");
    wishAdapter = new WishRowAdaptor(getActivity(), R.layout.row_wish,
            this.getNotifications());


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

    // We can now setup the PullToRefreshLayout
    ActionBarPullToRefresh.from(getActivity())

            // We need to insert the PullToRefreshLayout into the Fragment's ViewGroup
            .insertLayoutInto(container)

                    // 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(this)
            .setup(mPullToRefreshLayout);


    setListAdapter(wishAdapter);
    // View logv = inflater.inflate(R.layout.row_wish, null);
    // return logv;
    return super.onCreateView(inflater, container, savedInstanceState);

}

.listener(this)上面的代码中出现以下错误。

    listener (uk.co.senab.actionbarpulltorefresh.library.listeners.OnRefreshListener) in  
 SetupWizard cannot be applied to (com.wishberg.fragment.NotificationFragment)

我做错了什么?

N.B。我完全不喜欢android。

1 个答案:

答案 0 :(得分:0)

你可以尝试一下吗?

        @Override
        public View onCreateView(LayoutInflater inflater, ViewGroup container,
                Bundle savedInstanceState) {
            // Inflate your layout
            View view = inflater.inflate(R.layout.layout_fragment, container, false);

            // Now give the find the PullToRefreshLayout and set it up
            mPullToRefreshLayout = (PullToRefreshLayout) view.findViewById(R.id.ptr_layout);
            ActionBarPullToRefresh.from(getActivity())
                    .allChildrenArePullable()
                    .listener(this)
                    .setup(mPullToRefreshLayout);

            return view;
        }

这是片段的布局文件:

<uk.co.senab.actionbarpulltorefresh.library.PullToRefreshLayout
    xmlns:android="http://schemas.android.com/apk/res/android"
    android:id="@+id/ptr_layout"
    android:layout_width="match_parent"
    android:layout_height="match_parent">

    <ScrollView xmlns:android="http://schemas.android.com/apk/res/android"
        android:id="@+id/ptr_scrollview"
        android:layout_width="match_parent"
        android:layout_height="match_parent"
        android:padding="8dp"
        android:scrollbarStyle="outsideInset">

        <LinearLayout
            android:layout_height="wrap_content"
            android:layout_width="match_parent"
            android:orientation="vertical">

            <TextView
                android:layout_width="match_parent"
                android:layout_height="wrap_content"
                android:text="Lorem ipsum dolor sit amet, consectetur adipiscing elit. Donec sollicitudin mauris varius lacus porttitor eget blandit massa facilisis." />
        </LinearLayout>

    </ScrollView>
</uk.co.senab.actionbarpulltorefresh.library.PullToRefreshLayout>