检测向上滚动在 ListView 中向下滚动 [英] Detect Scroll Up & Scroll down in ListView
问题描述
我有以下要求:
- 首先,从服务器获取第 2 页的数据 &这几项填充在 ListView 中.
考虑到上一页和下一页在场景中可用,已添加以下代码:
Considering that both the prev page & next page are available in a scenario, the following code has been added:
if(prevPageNo > 0){
mListViewActual.setOnScrollListener(this);
}
if(nextPageNo > 0){
mListViewActual.setOnScrollListener(this);
}
我应该设置什么条件来检测向上滚动&向下滚动以下方法:
What conditions should I put to detect scroll up & scroll down on the following methods:
- void onScroll(AbsListView view, int firstVisibleItem, intvisibleItemCount, int totalItemCount)
- void onScrollStateChanged(AbsListView view, int scrollState)
动作后:向上滚动&检测到向下滚动,因此将使用上一页或下一页调用服务,以获取要在 Listview 中填充的项目.
After the action: scroll up & scroll down is detected , accordingly a service will be called with either the prev page no or next page no , to fetch the items to be populated in the Listview.
任何输入都会有所帮助.
Any inputs will be helpful.
浏览了以下链接,但没有返回正确的向上滚动/向下滚动操作:
Gone through the following links but its not returning the correct scroll up / scroll down action:
推荐答案
尝试使用 setOnScrollListener 并使用 scrollState 实现 onScrollStateChanged
try using the setOnScrollListener and implement the onScrollStateChanged with scrollState
setOnScrollListener(new OnScrollListener(){
public void onScroll(AbsListView view, int firstVisibleItem, int visibleItemCount, int totalItemCount) {
// TODO Auto-generated method stub
}
public void onScrollStateChanged(AbsListView view, int scrollState) {
// TODO Auto-generated method stub
final ListView lw = getListView();
if(scrollState == 0)
Log.i("a", "scrolling stopped...");
if (view.getId() == lw.getId()) {
final int currentFirstVisibleItem = lw.getFirstVisiblePosition();
if (currentFirstVisibleItem > mLastFirstVisibleItem) {
mIsScrollingUp = false;
Log.i("a", "scrolling down...");
} else if (currentFirstVisibleItem < mLastFirstVisibleItem) {
mIsScrollingUp = true;
Log.i("a", "scrolling up...");
}
mLastFirstVisibleItem = currentFirstVisibleItem;
}
}
});
这篇关于检测向上滚动在 ListView 中向下滚动的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!