简体   繁体   中英

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)

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. When that is true, it's fetching more items from the URL.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

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