If you apply ListView inside ScrollView, then the items of ListView will not scroll. By default the scrolling of ListView will not work if defined inside ScrollView. To make the scrolling work, use the onTouchListener. Below is the code to make listview scrolling work.
private void scrollListView() {
myListView.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)