关于SwipeRefreshLayout的刷新事件

--关于SwipeRefreshLayout使用的小记录
我们常见的SwipeRefreshLayout包裹Recyclerview,实现下拉加载-更新数据,常见布局例如:

<?xml version="1.0" encoding="utf-8"?>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
    android:layout_width="match_parent"
    android:layout_height="match_parent"
    android:orientation="vertical">

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

        <android.support.v7.widget.RecyclerView
            android:id="@+id/recyclerview"
            android:layout_width="match_parent"
            android:layout_height="match_parent"
            android:background="@android:color/transparent"
            android:fadeScrollbars="true"
            android:scrollbars="vertical" />
    </android.support.v4.widget.SwipeRefreshLayout>
</LinearLayout>

超级简单的布局,在Activity或者Fragment中,我们想在打开当前View时候,使SwipeRefreshLayout处于加载状态,例如在Activity的onCreate方法中,初始化SwipeRefreshLayout操作后调用setRefreshing方法:

SwipeRefreshLayout  refreshlayout = (SwipeRefreshLayout) findviewbyId(R.id.refreshlayout );
refreshlayout .setRefreshing(true);

编译运行,没有效果;
真正调用的方法:

  refreshlayout.post(new Runnable() {
            @Override
            public void run() {
           refreshlayout.setRefreshing(true);     
            }
        });

取消加载效果则

refreshlayout.post(() -> refreshlayout.setRefreshing(false));
refreshlayout.setRefreshing(false);

都可以

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值