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!