Reputation: 3906
I've implemented ListView in my application and working on onScrollListener. The ListView is working fine and in the onScroll() method of the onScrollListener, i'm trying to show a progressbar when the user has scrolled to the bottom.
The problem is that the listener doesn't stop listening and there are multiple progressbar loading on the screen if the user is trying to scroll even more. I don't have any idea how to solve this. I want the onScrollListener to stop listening when the progressbar shows.
Please help
list.setOnScrollListener(new OnScrollListener() {
@Override
public void onScrollStateChanged(AbsListView view, int scrollState) {
}
@Override
public void onScroll(AbsListView view, int firstVisibleItem,
int visibleItemCount, int totalItemCount) {
if (list.getLastVisiblePosition() == list.getAdapter().getCount() -
&& list.getChildAt(list.getChildCount() - 1).getBottom() <= list.getHeight()) {
ProgressBar pb = new ProgressBar(getActivity());
pb.setLayoutParams(pbParams);
linearLayout.addView(pb);
}
}
});
Thanks in advance
Upvotes: 0
Views: 967
Reputation: 25048
Can't you just check to see if there is already a progress bar and not add another?
Upvotes: 1