How to trigger an event when scrollView reach the bottom with Android?

前端 未结 5 1000
情话喂你
情话喂你 2020-12-10 03:48

Im looking for an event that I can use on the scrollView to be fired when the user has scrolled to the bottom.

E.g my list of items should be extended with more item

5条回答
  •  野趣味
    野趣味 (楼主)
    2020-12-10 03:50

    I had the same problem and I solved it by using the ListView (automatically adds ScrollView if needed) and setting OnScrollListener.

    Here is a code sample:

            tableListView.setOnScrollListener(new OnScrollListener() {
    
            public void onScrollStateChanged(AbsListView view, int scrollState) {
    
            }
    
            public void onScroll(AbsListView view, int firstVisibleItem,
                    int visibleItemCount, int totalItemCount) {
                if (visibleItemCount == totalItemCount)
                // too little items (ScrollView not needed)
                {
                    java.lang.System.out.println("too little items to use a ScrollView!");
                }
                else {
                    if ((firstVisibleItem + visibleItemCount) == totalItemCount) {
                        // put your stuff here
                        java.lang.System.out.println("end of the line reached!");
                    }
                }
    
            }
        });
    

提交回复
热议问题