Binding onScrolling listener to the android ListView

前端 未结 3 1613
伪装坚强ぢ
伪装坚强ぢ 2020-12-30 10:36

just wanted to ask is there a possibility to bind some listener to the ListView scroll event.

What I would like to achieve is that once ListView have been scrolled t

相关标签:
3条回答
  • 2020-12-30 10:49

    used

    if (++visibleItemCount > totalItemCount)

    instead

    if (++firstVisibleItem + visibleItemCount > totalItemCount)

    0 讨论(0)
  • 2020-12-30 10:50

    Just to extrapolate on TomTo's answer, some thoughts on how you might do this (theoretical, I haven't tried this in practice):

    ListView lv = (ListView)findViewById(R.id.list_view);
    lv.setOnScrollListener(new OnScrollListener() {
        @Override
        public void onScroll(AbsListView view, int firstVisibleItem, 
            int visibleItemCount, int totalItemCount) {
            //Check if the last view is visible
            if (++firstVisibleItem + visibleItemCount > totalItemCount) {
                //load more content
            }
        }
    });
    

    Since firstVisibleItem is returns an index (0-based), I increment by one to get the actual item number. Then, if that, plus the number of visible items, is greater than the total number of items, then in theory the last view should be visible. Shouldn't be a problem, but keep in mind this isn't called till the scrolling is finished.

    0 讨论(0)
  • 2020-12-30 11:03

    AbsListView.OnScrollListener ?

    0 讨论(0)
提交回复
热议问题