Android implements dynamic loading of ListView data
- 2020-12-20 03:45:07
- OfStack
An example of Android shows how to implement dynamic loading of ListView data. To share for your reference, the details are as follows:
list.setOnScrollListener(new OnScrollListener() {
// Add the scroll bar and roll to the bottom to load the remaining elements
public void onScrollStateChanged(AbsListView view, int scrollState) {
// if (scrollState == OnScrollListener.SCROLL_STATE_IDLE) {// This method works, but the scroll bar also fires when it rolls to the top
// Toast.makeText(TestListScroll.this, "OK", Toast.LENGTH_SHORT).show();
// bindViewData();bindViewData
// }
// This approach fits the bill: scroll down and load the data
if(view.getLastVisiblePosition() == (view.getCount() -1)){
bindViewData();// Methods for loading data
}
}
// The following method can achieve scroll loading per scroll 1 Bar is loaded at the bottom 1 The article.
public void onScroll(AbsListView view, int firstVisibleItem, int visibleItemCount, int totalItemCount) {
// The rolling load
//// Toast.makeText(TestListScroll.this, "OK" + firstVisibleItem + "|" + visibleItemCount + "|" + totalItemCount, Toast.LENGTH_SHORT).show();
// int lastItem = firstVisibleItem + visibleItemCount;
//// Toast.makeText(TestListScroll.this, "OK" + listItem.size() + firstVisibleItem + visibleItemCount + lastItem , Toast.LENGTH_SHORT).show();
// if (listItem.size() == lastItem && listItemAdapter.getCount() > 0) {
// start = end;
// end = end + 1;
//
// bindViewData();
// }
}
});
For more information about Android controls, please refer to the Android Control Usage Summary.
I hope this article has been helpful in Android programming.