滚动时不调用网格onScroll

时间:2015-06-09 03:09:41

标签: java android gridview

出于某种原因onScroll仅在网格加载期间触发,而不是在网格滚动操作期间触发。有什么想法吗?

 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) {

            }
        };

0 个答案:

没有答案