Scrolling with Multiple ListViews for Android

Forward touch event from touched view to other views. All your views will be synchronized expand/collapsed too.

   OnTouchListener mOnTouch = new OnTouchListener()
    {
        @Override
        public boolean onTouch(View v, MotionEvent event)
        {            
            MotionEvent newEvent = MotionEvent.obtain(event);
            switch(event.getAction()){  
            case MotionEvent.ACTION_MOVE:
                if(mTouched == null){
                    mTouched = v;
                }
                mMovingFlag = true;
                break;
            case MotionEvent.ACTION_UP:
                if(mMovingFlag==false){
                    newEvent.setAction(MotionEvent.ACTION_CANCEL);
                }
                mMovingFlag = false;
                break;
            default:
                mMovingFlag = false;
                if(mTouched != null && mTouched.equals(v)){
                    mTouched = null;
                }
                break;

            }
            if(mTouched == null || mTouched.equals(v)){
                int items = mLayoutWithListViews.getChildCount();
                for(int list=0; list<items; list++){
                    AbsListView listView =mLayoutWithListViews.getChildAt(list));
                    if(listView != v){
                         listView.onTouchEvent(newEvent);
                    }
                }
            }
            return false;
        }
    };

Leave a Comment