Android Endless List

后端 未结 10 1292
梦如初夏
梦如初夏 2020-11-22 02:52

How can I create a list where when you reach the end of the list I am notified so I can load more items?

10条回答
  •  花落未央
    2020-11-22 03:43

    I've been working in another solution very similar to that, but, I am using a footerView to give the possibility to the user download more elements clicking the footerView, I am using a "menu" which is shown above the ListView and in the bottom of the parent view, this "menu" hides the bottom of the ListView, so, when the listView is scrolling the menu disappear and when scroll state is idle, the menu appear again, but when the user scrolls to the end of the listView, I "ask" to know if the footerView is shown in that case, the menu doesn't appear and the user can see the footerView to load more content. Here the code:

    Regards.

    listView.setOnScrollListener(new OnScrollListener() {
    
        @Override
        public void onScrollStateChanged(AbsListView view, int scrollState) {
            // TODO Auto-generated method stub
            if(scrollState == SCROLL_STATE_IDLE) {
                if(footerView.isShown()) {
                    bottomView.setVisibility(LinearLayout.INVISIBLE);
                } else {
                    bottomView.setVisibility(LinearLayout.VISIBLE);
                } else {
                    bottomView.setVisibility(LinearLayout.INVISIBLE);
                }
            }
        }
    
        @Override
        public void onScroll(AbsListView view, int firstVisibleItem,
                int visibleItemCount, int totalItemCount) {
    
        }
    });
    

提交回复
热议问题