Skip to content

Instantly share code, notes, and snippets.

@Neferetheka
Created May 9, 2015 10:21
Show Gist options
  • Save Neferetheka/872d7a6d863f76169152 to your computer and use it in GitHub Desktop.
Save Neferetheka/872d7a6d863f76169152 to your computer and use it in GitHub Desktop.
FixedSwipeRefreshLayout
import android.content.Context;
import android.support.v4.widget.SwipeRefreshLayout;
import android.util.AttributeSet;
/**
* Fix for SwipeRefreshLayout, which doesn't display the loading indicator if the onMeasure method hasn't been called.
* From https://code.google.com/p/android/issues/detail?id=77712
*/
public class FixedSwipeRefreshLayout extends SwipeRefreshLayout {
private boolean mMeasured = false;
private boolean mPreMeasureRefreshing = false;
public FixedSwipeRefreshLayout(Context context) {
super(context);
}
public FixedSwipeRefreshLayout(Context context, AttributeSet attrs) {
super(context, attrs);
}
@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;
}
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment