Reputation: 1793
I'm using SwipeRefreshLayout
and want to set it refreshing after I create the Activity
, but the setRefreshing(true)
do not work. So I find this question in SO:SwipeRefreshLayout setRefreshing not showing indicator initially.
I choose to override SwipeRefreshLayout to store local refreshing flag:
public class MyRefreshLayout extends SwipeRefreshLayout {
public MyRefreshLayout(Context context) {
super(context);
}
public MyRefreshLayout(Context context, AttributeSet attrs) {
super(context, attrs);
}
private boolean mMeasured = false;
private boolean mPreMeasureRefreshing = false;
@Override
public void onMeasure(int widthMeasureSpec, int heightMeasureSpec) {
super.onMeasure(widthMeasureSpec, heightMeasureSpec);
if (!mMeasured) {
mMeasured = true;
setRefreshing(mPreMeasureRefreshing);
}
}
@Override
public void setRefreshing(boolean refreshing) {
if (mMeasured) {
super.setRefreshing(refreshing);
} else {
mPreMeasureRefreshing = refreshing;
}
}
}
It will refresh after I create activity but the OnRefreshListener
do not be called. Here is my init code:
mRefreshLayout = (MyRefreshLayout) findViewById(R.id.refresh_layout);
mRefreshLayout.setColorSchemeResources(R.color.holo_blue_dark, R.color.holo_blue_light, R.color.holo_green_light, R.color.holo_green_light);
mRefreshLayout.setOnRefreshListener(new SwipeRefreshLayout.OnRefreshListener() {
@Override
public void onRefresh() {
mRefreshLayout.setRefreshing(false);
}
});
mRefreshLayout.setRefreshing(true);
I can't find relate question , please help , thanks!
Upvotes: 0
Views: 2441
Reputation: 463
You can find the solution in Min2's answer for the solution on how to call the listener
SwipeRefreshLayout trigger programmatically
Upvotes: 0
Reputation: 1793
I found that I misunderstood the OnRefreshListener
. The doc says:
Classes that wish to be notified when the swipe gesture correctly triggers a refresh should implement this interface.
So If I call mRefreshLayout.setRefreshing(true);
. It is not a swipe gesture , the listener won't be called!
Upvotes: 3