美文网首页
刷新功能

刷新功能

作者: 今天也要努力呀y | 来源:发表于2019-10-16 20:54 被阅读0次

用SwipeRefreshLayout,一般是包裹一个recyclerview

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

            <android.support.v7.widget.RecyclerView
                android:id="@+id/news_list"
                android:layout_width="match_parent"
                android:layout_height="match_parent">

            </android.support.v7.widget.RecyclerView>
        </android.support.v4.widget.SwipeRefreshLayout>

然后去

    private SwipeRefreshLayout refreshLayout;
    refreshLayout = findViewById(R.id.refresh);
    refreshLayout.setColorSchemeResources(R.color.colorPrimary);
    initRefresh();

initData里就是你自己写得请求数据了

private void initRefresh() {
        refreshLayout.setOnRefreshListener(new SwipeRefreshLayout.OnRefreshListener() {
            @Override
            public void onRefresh() {
                initData();
            }
        });
    }

更新完之后记得停止转动

refreshLayout.setRefreshing(false);

相关文章

网友评论

      本文标题:刷新功能

      本文链接:https://www.haomeiwen.com/subject/jwqpmctx.html