How to check if a my ListView has scrollable number of items?

后端 未结 8 653
故里飘歌
故里飘歌 2020-12-30 04:00

How do you know if your ListView has enough number of items so that it can scroll?

For instance, If I have 5 items on my ListView all of it will be displayed on a si

相关标签:
8条回答
  • 2020-12-30 04:48

    You cannot detect this before android render the screen with the listView. However, you can absolutely detect this post-render.

    boolean willMyListScroll() {        
       if(listView.getLastVisiblePosition() + 1 == listView.getCount()) {
          return false;
       }
    
       return true;             
    }
    

    What this does is check if the listView visible window contains ALL your list view items. If it can, then the listView will never scroll and the getLastVisiblePosition() will always be equal to the total number of items in the list's dataAdapter.

    0 讨论(0)
  • 2020-12-30 04:48

    Use the setOnScrollListener, by applying the callback to OnScrollListener, you can determine if scrolling is taking place using the pre-defined constants and handle the situation accordingly.

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