1. 程式人生 > >android listview判斷是否滑動到頂部還是底部

android listview判斷是否滑動到頂部還是底部

listView.setOnScrollListener(new AbsListView.OnScrollListener() {
            @Override
            public void onScrollStateChanged(AbsListView view, int scrollState) {
            }

            @Override
            public void onScroll(AbsListView view, int firstVisibleItem, int visibleItemCount, int totalItemCount) {
                if (firstVisibleItem == 0) {
                    Toast.makeText(MyActivity.this, "滑到頂部",1).show();
                }
                if (visibleItemCount + firstVisibleItem == totalItemCount) {
                    Toast.makeText(MyActivity.this, "滑到底部",1).show();
                }