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)