Scrolling with Multiple ListViews for Android

Andrew Burgess picture Andrew Burgess · Nov 20, 2008 · Viewed 27.4k times · Source

I'm completely stumped on this one. I have three different lists that need to be displayed on the screen. It's completely possible that the lists will extend past the bottom edge of the screen, so I would need scrolling.

I've tried using a ScrollView with a LinearLayout child, and putting my ListViews in the LinearView, but all of the ListViews lock to a fixed height with scroll bars. Using other kinds of Layouts means no scrolling.

Does anyone have any suggestions, or will I need to programmatically add the list items to some layout and hope for the best?

Answer

Richard picture Richard · Jun 29, 2011

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