ListView没有响应滚动而是触摸

时间:2014-10-21 17:15:57

标签: android listview

当我的listview停止滚动时,我会在其上调用adapter.notifyDataSetChanged();。我在

时也打电话给notifyDataSetChanged()
  1. 用户触摸列表视图(列表不滚动)

  2. 从列表中移除他的手指(列表不滚动)

  3. 但是当listview停止滚动并且我尝试立即再次滚动它时,它没有响应。它需要1-2秒才能再次响应滚动。没有任何线索

    onTouchListener的

    Code

     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

    Code

     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()
    
                    }
    
                }
            });
    

0 个答案:

没有答案