Created
October 6, 2014 03:38
-
-
Save huangcd/5c65f6a229e2a1f5afb7 to your computer and use it in GitHub Desktop.
SwipeRefreshLayout and ListView
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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