I have a grid view and want to update the items in grid view after the end of list is reached. To implement this i decided to use OnScrollListener. But the behavior of OnScrollListener is strange as it calls my method to update grid view many times..
@Override
public void onScroll(AbsListView view, int firstVisibleItem,
int visibleItemCount, int totalItemCount) {
// TODO Auto-generated method stub
if (firstVisibleItem + visibleItemCount >= totalItemCount) {
// End has been reached
// Call method to update
Log.i("CountShit", String.valueOf(firstVisibleItem) + " + "
+ String.valueOf(visibleItemCount) + " >= "
+ String.valueOf(totalItemCount));
}
}
});
and in my log the if conditioin is called many times as the onScrollListener keeps on listening the scroll i guess ..
09-29 14:06:10.338: I/CountShit(23640): 12 + 8 >= 20
09-29 14:06:10.353: I/CountShit(23640): 12 + 8 >= 20
09-29 14:06:10.369: I/CountShit(23640): 12 + 8 >= 20
09-29 14:06:10.385: I/CountShit(23640): 12 + 8 >= 20
09-29 14:06:10.400: I/CountShit(23640): 12 + 8 >= 20
09-29 14:06:10.424: I/CountShit(23640): 14 + 6 >= 20
09-29 14:06:10.439: I/CountShit(23640): 14 + 6 >= 20
09-29 14:06:10.455: I/CountShit(23640): 14 + 6 >= 20
09-29 14:06:10.470: I/CountShit(23640): 14 + 6 >= 20
09-29 14:06:10.486: I/CountShit(23640): 14 + 6 >= 20
Is there a way such that if i hit the end of list first time, my upate method is called.. and then if the user scrolls up or down or whatever the method should not be called again! (until i reach the end of my updated list ofcourse).
I was able to solve the problem by adding some variables
and checking the following condition ..
totalDataCount -> Variable which stores the total count of data your api gets you
previousTotal -> Variable which stores the previous total count. by default it is set to zero.
loading -> Boolean value set to false by default.
Declare all these variable in your activity and not in inner class(below)
This code will work below :-
You are seeking an endless view. You have to create an endless scroll listener and apply it to GridView. Try below code;
Initialize GridView and apply adapter
EndlessScrollListener
Source