Skip to content

Instantly share code, notes, and snippets.

@huangcd
Created October 6, 2014 03:38
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save huangcd/5c65f6a229e2a1f5afb7 to your computer and use it in GitHub Desktop.
Save huangcd/5c65f6a229e2a1f5afb7 to your computer and use it in GitHub Desktop.
SwipeRefreshLayout and ListView
newsList.setOnScrollListener(new AbsListView.OnScrollListener() {
@Override
public void onScrollStateChanged(AbsListView view, int scrollState) {
}
@Override
public void onScroll(
AbsListView view, int firstVisibleItem,
int visibleItemCount, int totalItemCount) {
boolean enable = false;
if (newsList != null && newsList.getChildCount() > 0) {
// check if the first item of the list is visible
boolean firstItemVisible = newsList.getFirstVisiblePosition() == 0;
// check if the top of the first item is visible
boolean topOfFirstItemVisible = newsList.getChildAt(0).getTop() == 0;
// enabling or disabling the refresh layout
enable = firstItemVisible && topOfFirstItemVisible;
}
refreshLayout.setEnabled(enable);
}
});
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment