简体   繁体   中英

load more rows in listactivity in android

what i am implementing ListActivity with custom row. I am wondering if there id any possibility to load more rows when the listview reaches the bottom . I have found this tutorial Endless scrolling in listview

Please help me understand how it works

ListView allows you to register an OnScrollListener . It's onScroll -Method gets called everytime the user scrolls in the ListView. By doing some calculations with the parameters provided, you can check whether the user reached the end of the ListView. To quote some code from your example:

if (totalItemCount - visibleItemCount) <= (firstVisibleItem + visibleThreshold)) {
   // we are less or equal to visibleThreshold items away from the end      
}

There, you can just load some more items from wherever you get them, put them into your Adapter and call it's notifyDataSetChanged() -Method. Make sure you call that method from your UI-Thread though, for example by using the runOnUiThread -Method of your Activity.

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