怎样实现SwipeRefreshLayout的自动刷新

2025-01-01 06:06:54
推荐回答(1个)
回答1:

方法一、
①在onWindowFocusChanged()方法中,设置为刷新状态为true
@Override
public void onWindowFocusChanged(boolean hasFocus) {
super.onWindowFocusChanged(hasFocus);
mSwipeRefreshLayout.setRefreshing(true);
}

②在获取数据完成后设置刷新状态为false
if (mSwipeRefreshLayout.isRefreshing()) {
mSwipeRefreshLayout.setRefreshing(false);
}

方法二、
①调用mSwipeRefreshLayout.measure()方法后,设置刷新状态为true
//手动调用,通知系统去测量
mSwipeRefreshLayout.measure(0,0);
mSwipeRefreshLayout.setRefreshing(true);

②在获取数据完成后设置刷新状态为false
if (mSwipeRefreshLayout.isRefreshing()) {
mSwipeRefreshLayout.setRefreshing(false);
}