安卓SwipeRefreshLayout使用

本文介绍了如何在Android应用中实现页面自动刷新功能,并详细解释了如何通过手动调用回调方法来触发刷新。此外,还探讨了解决刷新功能与ListView组件之间潜在冲突的方法,确保只有在合适的情况下才进行刷新。

1.实现自动刷新

希望加载页面的时候自动刷新onrefresh方法自动不会执行

要自动执行刷新,要自己手动调用哪个回调方法。才会走Onrefresh


refreshLayout = (SwipeRefreshLayout) view.findViewById(R.id.refreshLayout);
refreshLayout.setOnRefreshListener(this);
refreshLayout.post(new Runnable() {
    @Override
    public void run() {
        refreshLayout.setRefreshing(true);
    }
});
onRefresh();
2.结合listView使用的时候,回有冲突,不停的调用刷新方法,这时候可以根据是否是listView第一个条目,来判断是否允许刷新


if (GeneralUtils.isEmpty(mList)) {
    LogUtils.debug("可以刷新");//如果没有数据。则可以刷新
    mRefreshLayout.setEnabled(true);
    return;
}
boolean enable = true;
if (ll_homeworks != null && ll_homeworks.getChildCount() > 0) {
    // check if the first item of the list is visible
    boolean firstItemVisible = ll_homeworks.getFirstVisiblePosition() == 0;
    // check if the top of the first item is visible
    enable = firstItemVisible;
}
mRefreshLayout.setEnabled(enable);

评论
成就一亿技术人!
拼手气红包6.0元
还能输入1000个字符
 
红包 添加红包
表情包 插入表情
 条评论被折叠 查看
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值