简体   繁体   English

Android-如何在滚动视图中使用列表视图加载更多项目?

[英]Android-How to Load more items using list view inside scroll view?

I need to load more items when the page reached at the end of the page and page contains list and other views.For this i used list view for the list of items when is below all other views and kept inside scroll view.So here my problem is list view is not growing height, i googled and applied to extend the list view height but it s not loading the more items while scrolling down.Please any body suggest me how can i reach this task. 当我到达页面末尾的页面并且页面包含列表和其他视图时,我需要加载更多项目。为此,当所有其他视图下方并保留在滚动视图中时,我将列表视图用于项目列表。问题是列表视图没有增加高度,我用谷歌搜索并应用于扩展列表视图的高度,但是在向下滚动时它不会加载更多项目。请任何人建议我如何完成此任务。 Thanks in advance. 提前致谢。

I came across this link which contains the full source code on how to more items when reaching the end of scroll view. 我碰到了链接,其中包含有关到达滚动视图末尾时如何添加更多项目的完整源代码。

Let me explain how he achieved this: What you need can be achieved by this part of the code (line 86 - 102) 让我解释一下他是如何实现的:通过代码的这一部分可以实现您所需要的(86-102行)

listView.setOnScrollListener(new OnScrollListener(){

    @Override
    public void onScrollStateChanged(AbsListView view, int scrollState) {}

    @Override
    public void onScroll(AbsListView view, int firstVisibleItem,
      int visibleItemCount, int totalItemCount) {

          int lastInScreen = firstVisibleItem + visibleItemCount;    
          if((lastInScreen == totalItemCount) && !(loadingMore)){     
            String url = "http://10.0.2.2:8080/CountryWebService" + 
            "/CountryServlet";
           grabURL(url); 
           }
      }
})

So in the above code, you can see that setOnScrollListener is called and in the onScroll, it's checked if the last item in the current listview is actually the last item. 因此,在上面的代码中,您可以看到setOnScrollListener被调用,并且在onScroll中,将检查当前列表视图中的最后一项是否实际上是最后一项。 When that is true, it's fetching more items from the URL. 如果是这样,它将从URL中获取更多项。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM