我想更新我的ListView,当我向下滚动我这样做:
mConnectionList.setOnTouchListener(new View.OnTouchListener() {
@Override
public boolean onTouch(View v, MotionEvent event) {
int action = event.getAction();
switch (action) {
case MotionEvent.ACTION_DOWN:
if( mConnectionList.getLastVisiblePosition() == connectionList.size()-1 ){
getConnections();
}
break;
case MotionEvent.ACTION_UP:
isCrollingDown.set(false);
break;
default:
}
return false;
}
});
不过,这并不corretlly工作,它更新,当我向下滚动,更新时,我向上滚动
此外,我尝试这样做,但它不不coretly工作过:
mConnectionList.setOnScrollListener(new AbsListView.OnScrollListener() {
@Override
public void onScroll(AbsListView view, int firstVisibleItem, int visibleItemCount, int totalItemCount) {
}
@Override
public void onScrollStateChanged(AbsListView view, int scrollState) {
// Log.e("a0","a " + mConnectionList.getLastVisiblePosition());
// if(mConnectionList.getLastVisiblePosition() == connectionList.size()-1 ){
getConnections();
}
}
});
尝试向下滚动列表视图这种方法,并选择最后一排,因此将滚动到视图。
private void scrollListBottom() {
myListView.post(new Runnable() {
@Override
public void run() {
listView.setSelection(listAdapter.getCount() - 1);
}
});
}
myListView.setOnTouchListener(new OnTouchListener()
@Override
public boolean onTouch(View v, MotionEvent event) {
v.getParent().requestDisallowInterceptTouchEvent(true);
return false;
}
});
你应该尝试这样的。
scrollView.setOnScrollChangeListener(new NestedScrollView.OnScrollChangeListener() {
@Override
public void onScrollChange(NestedScrollView v, int scrollX, int scrollY, int oldScrollX, int oldScrollY) {
if (scrollY > oldScrollY) {
Log.e("SCROLL", "Scroll DOWN"+scrollY);
}
if (scrollY < oldScrollY) {
Log.e("SCROLL", "Scroll UP"+scrollY);
}
if (scrollY == 0) {
Log.e("SCROLL", "TOP SCROLL"+scrollY);
}
if (scrollY == (v.getChildAt(0).getMeasuredHeight() - v.getMeasuredHeight())) {
Log.e("SCROLL", "BOTTOM SCROLL"+scrollY);
}
}
});
使用这个你可以检测你的滚动方向,然后更新您的列表希望这会帮助你。