【问题标题】:Android ListView automatically Load more data when scroll to the topAndroid ListView 滚动到顶部时自动加载更多数据
【发布时间】:2014-06-17 18:59:15
【问题描述】:

有一个关于Android ListView automatically Load more data when scroll to the Bottom 的问题。但我需要的与那个问题完全相反。我已经颠倒了第一个答案,但它没有用,如果列表视图为空,则在第一个答案中没有调用任何滚动事件。所以帮我检测android listview中的向上滚动事件来更新它。

【问题讨论】:

    标签: android listview android-listview scroll


    【解决方案1】:

    当您滚动到列表视图的顶部时,以下逻辑将用于加载更多数据。

    listview.setOnScrollListener(new AbsListView.OnScrollListener(){
        @Override
        public void onScrollStateChanged (AbsListView view,int scrollState){
        currentScrollState = scrollState;
          if (currentVisibleItemCount > 0 && currentScrollState == SCROLL_STATE_IDLE) {
            if (currentFirstVisibleItem == 0) {
    
                // getMessages(); //write what you want to do when you scroll up to the end of listview.
    
            }
          }
        }
    
        @Override
        public void onScroll (AbsListView view,int firstVisibleItem, int visibleItemCount,
        int totalItemCount){
         currentFirstVisibleItem = firstVisibleItem;
         currentVisibleItemCount = visibleItemCount;
         currentTotalItemCount = totalItemCount;
        }
        });
    

    希望这会有所帮助。

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 1970-01-01
      • 2016-07-04
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2011-02-22
      • 1970-01-01
      相关资源
      最近更新 更多