Join the social network of Tech Nerds, increase skill rank, get work, manage projects...
 
  • How to scroll listview inside a ScrollView in Android.

    • 0
    • 0
    • 0
    • 0
    • 0
    • 0
    • 0
    • 0
    • 3.79k
    Comment on it

    Hello Friends

    Here I am going to share a very important code to make ListView scroll inside a ScrollView.

    Most of the Android developers says: Its not a good approach to put a ListView inside a ScrollView because a ListView is already a scrollview, but some times its really needed in project.

    I have wasted a lot of precious time in searching the solution, so I dont want someone to do same.

    To achieve this functionality you have to follow the code given below.

    You just have to put this code on your list-view in your Activity.

    yourListView.setOnTouchListener(new ListView.OnTouchListener() {
            @Override
            public boolean onTouch(View v, MotionEvent event) {
                int action = event.getAction();
                switch (action) {
                case MotionEvent.ACTION_DOWN:
                    // Disallow ScrollView to intercept touch events.
                    v.getParent().requestDisallowInterceptTouchEvent(true);
                    break;
    
                case MotionEvent.ACTION_UP:
                    // Allow ScrollView to intercept touch events.
                    v.getParent().requestDisallowInterceptTouchEvent(false);
                    break;
                }
    
                // Handle ListView touch events.
                v.onTouchEvent(event);
                return true;
            }
        });
    

 0 Comment(s)

Sign In
                           OR                           
                           OR                           
Register

Sign up using

                           OR                           
Forgot Password
Fill out the form below and instructions to reset your password will be emailed to you:
Reset Password
Fill out the form below and reset your password: