Check If Android Listview Is Scrolled Down To The Last Item
I have a listview in which there are several items. I want to check whether the list is scrolled down to the last item, in which case I want to run another method.How to do that?
Solution 1:
at first set isLoading = false;
in the constructore or onCreate
method
mListView.setOnScrollListener(newOnScrollListener() {
@OverridepublicvoidonScrollStateChanged(AbsListView view, int scrollState) {
}
@OverridepublicvoidonScroll(AbsListView view, int firstVisibleItem, int visibleItemCount, int totalItemCount) {
if (mListView.getAdapter() == null)
return ;
if (mListView.getAdapter().getCount() == 0)
return ;
intl= visibleItemCount + firstVisibleItem;
if (l >= totalItemCount && !isLoading) {
// It is time to add new data. We call the listener
isLoading = true;
loadData();
}
}
});
and in function loadData
you do something like:
publicvoidloadData() {
// send your request// receive it by callback or asynctask
yourDataList.addAll(newItems);
adapter.notifyDataSetChanged();
isLoading = false;
}
Post a Comment for "Check If Android Listview Is Scrolled Down To The Last Item"