我有一个 ListView,正如问题所暗示的那样,我正在延迟加载图像。问题是这个方法覆盖了我的自定义 onScrollListener。我尝试使用:
aq.id(listview).scrolled(new customScrollListener());
aq.id(listview).adapter(myAdapter);
这两行在调用活动类中,我在加载列表中的所有数据后执行此操作。即使在此之后, scrollListener 似乎也没有工作。我哪里错了?有任何想法吗?
更新 - CustomScrollListener:
private class CustomScrollListener implements OnScrollListener {
private Context context;
private int visibleThreshold = 0;
private int currentPage = 0;
private int previousTotal = 0;
private boolean loading = true;
CustomScrollListener(Context context) {
this.context = context;
}
CustomScrollListener(int visibleThreshold) {
this.visibleThreshold = visibleThreshold;
}
@Override
public void onScroll(AbsListView view, int firstVisibleItem,
int visibleItemCount, int totalItemCount) {
if (loading) {
if (totalItemCount > previousTotal) {
loading = false;
previousTotal = totalItemCount;
currentPage++;
}
}
if (!loading && (totalItemCount - visibleItemCount) <= (firstVisibleItem + visibleThreshold) && totalItemCount>10) {
// do something
}
}
@Override
public void onScrollStateChanged(AbsListView view, int scrollState) {
}
}