For some reason onScroll is triggered only during grid load and not during the grid scroll action. Any ideas ?
View view = findViewById(R.id.grid_view);
GridView gridView = (GridView)view;
gridView.setOnScrollListener( new GridScrollListener());
.......
.....
public class GridScrollListener implements AbsListView.OnScrollListener {
private int threshold = 2;
private int currentpage = 0;
private int previoustotal = 0;
private boolean loading = true;
public GridScrollListener(){}
public GridScrollListener(int threshold){
this.threshold = threshold;
}
//public void onScroll(AbsListView view, int firstVisibleItem, int visibleItemCount, int totalItemCount)
@Override
public void onScroll(AbsListView view, int firstVisibleItem, int visibleItemCount, int totalItemCount) {
Log.e(TAG,""+totalItemCount);
if(loading){
if(totalItemCount > previoustotal){
loading = false;
previoustotal = totalItemCount;
currentpage++;
}
}
if(!loading && (totalItemCount - visibleItemCount) <= (firstVisibleItem + threshold)){
loading = true;
}
}
@Override
public void onScrollStateChanged(AbsListView view, int scrollState) {
}
};