How can you limit the initial number of items in the ListView so that the first thirty entries are first loaded, then when the end of the list is reached, the next 30 entries are loaded, etc.
2 answers
- Hang scroll listener on ListView
- In it, determine that you have reached the end of the list.
- Run the task of adding items.
It is necessary to google
endless scrolling listView
and it's better to do it through RecyclerView
- it's easier there.
|
youListView.setOnScrollListener(new OnScrollListener() { public void onScroll(AbsListView view, int firstVisibleItem, int visibleItemCount, int totalItemCount) { if(firstVisibleItem+visibleItemCount == totalItemCount && totalItemCount!=0) { if(isLoading) { isLoading = false; additems(); } } } });
In the method of adding additional items, add the following 30 elements to the ArrayList. It is also necessary to create a boolean (flag) isLoading and, after adding, assign it the value true and call notifyDataSetChanged () .
|