当我的listview停止滚动时,我会在其上调用adapter.notifyDataSetChanged();
。我在
notifyDataSetChanged()
用户触摸列表视图(列表不滚动)
从列表中移除他的手指(列表不滚动)
但是当listview停止滚动并且我尝试立即再次滚动它时,它没有响应。它需要1-2秒才能再次响应滚动。没有任何线索
onTouchListener的 listView.setOnTouchListener(new OnTouchListener() {
@Override
public boolean onTouch(View v, MotionEvent event) {
if (event.getAction() == MotionEvent.ACTION_DOWN) {
if(mScrollStateOfListView==OnScrollListener.SCROLL_STATE_IDLE) {
if (!adapter.getAllItemsVisible()) {
doThings();
adapter.notifyDataSetChanged();
} else if (adapter.getAllItemsVisible() && adapter.getHighlightCurrentMonth()) {
doThings();
adapter.notifyDataSetChanged();
}
}
else if(mScrollStateOfListView==OnScrollListener.SCROLL_STATE_TOUCH_SCROLL){
listBeingTouched.set(true);
}
}
if (event.getAction() == MotionEvent.ACTION_UP) {
if(mScrollStateOfListView==OnScrollListener.SCROLL_STATE_IDLE) {
doThings();
listBeingTouched.compareAndSet(true,false);
adapter.notifyDataSetChanged();
}
else if(mScrollStateOfListView==OnScrollListener.SCROLL_STATE_TOUCH_SCROLL){
listBeingTouched.compareAndSet(true,false);
}
}
return false;
}
});
对于onscrollListener , listView.setOnScrollListener(new OnScrollListener() {
public void onScroll(AbsListView view, int firstVisibleItem, int visibleItemCount, int totalItemCount) {
}
public void onScrollStateChanged(AbsListView view, int scrollState) {
mScrollStateOfListView=scrollState;
if (scrollState == OnScrollListener.SCROLL_STATE_IDLE && !listBeingTouched.get()) {
listBeingTouched.set(true);
doThingsAndNotifyAdapterDataSet()
}
}
});