首页 > 解决方案 > SwipeRefreshLayout 刷新动画不会停止,尽管我设置了 swipeView.setRefreshing(false)

问题描述

我找到了一些答案,例如

SwipeRefreshLayout 刷新动画不会停止

加上其他一些问答,但直到现在我还没有找到我的解决方案,即使我也无法理解这个问题。

实际上这个类是 pageAdapter

我的代码是

@Override
public Object instantiateItem(ViewGroup container, int position) {

    View listView = LayoutInflater.from(container.getContext()).inflate(R.layout.fragment_common_list, container, false);
    swipeView = (SwipeRefreshLayout) listView.findViewById(R.id.nfs);
    swipeView.setColorSchemeResources(R.color.colorPrimary,
            R.color.colorAccent,
            R.color.yes,
            R.color.no);
    swipeView.setOnRefreshListener(new SwipeRefreshLayout.OnRefreshListener() {
                @Override
                public void onRefresh() {
                    (new Handler()).postDelayed(new Runnable() {
                        @Override
                        public void run() {
                            Log.d("SwipeView","Refrehing");
                            swipeView.setRefreshing(false);
                            Log.d("SwipeView ",swipeView.isRefreshing()+"");
                        }
                    }, 3000);
                }


            });
}

我的fragment_common_list视图是

<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:tools="http://schemas.android.com/tools"
android:id="@+id/constraintLayout"
android:layout_width="match_parent"
android:layout_height="match_parent">

<android.support.v4.widget.SwipeRefreshLayout
    android:id="@+id/nfs"
    android:layout_width="match_parent"
    android:layout_height="wrap_content"
    android:layout_marginTop="@dimen/tab_height">

    <ListView
        android:id="@+id/commonList"
        android:layout_width="match_parent"
        android:layout_height="wrap_content" />
</android.support.v4.widget.SwipeRefreshLayout>

标签: androidswiperefreshlayout

解决方案


解决方案:

代替:

swipeView = (SwipeRefreshLayout) listView.findViewById(R.id.nfs);

写:

swipeView = (SwipeRefreshLayout) findViewById(R.id.nfs);

如果是Activity, 声明它onCreate();

如果它在 中,则使用视图对象Fragment声明它。onCreateView()

试试看,希望对你有帮助。


推荐阅读