I have a ListView, first its scrolled down, now when we scroll up,it reach top most point. I want to detect that .Is there any way?I am developing application with api level
This question is old but I have a solution that works perfectly and it is possible that works for someone looking for a solution.
int limitRowsBDshow = 10; //size limit your list
listViewMessages.setOnScrollListener(new AbsListView.OnScrollListener() {
int counter = 1;
int currentScrollState;
int currentFirstVisibleItem;
int currentVisibleItemCount;
int currentTotalItemCount;
@Override
public void onScrollStateChanged(AbsListView view, int scrollState) {
this.currentScrollState = scrollState;
this.isScrollCompleted();
}
@Override
public void onScroll(AbsListView view, int firstVisibleItem, int visibleItemCount, int totalItemCount) {
this.currentFirstVisibleItem = firstVisibleItem;
this.currentVisibleItemCount = visibleItemCount;
this.currentTotalItemCount = totalItemCount;
}
private void isScrollCompleted() {
if (this.currentVisibleItemCount > 0 && this.currentScrollState == SCROLL_STATE_IDLE) {
/*** detect if there's been a scroll which has completed ***/
counter++;
if (currentFirstVisibleItem == 0 && currentTotalItemCount > limitRowsBDshow - 1) {
linearLay20msgMas.setVisibility(View.VISIBLE);
}
}
}
});
This code is found a time ago (here StackOverflow). But I can not find this to mention