In my app i did use scroll inside a Scrollview layout(root layout).when i did that the child scroll stopped scrolling.For this i found a solution code
childlistview.setOnTouchListener(new ListView.OnTouchListener() {
@Override
public boolean onTouch(View v, MotionEvent event) {
// TODO Auto-generated method stub
int action = event.getAction();
switch (action) {
case MotionEvent.ACTION_DOWN:
v.getParent().requestDisallowInterceptTouchEvent(true);
break;
case MotionEvent.ACTION_UP:
v.getParent().requestDisallowInterceptTouchEvent(false);
break;
}
v.onTouchEvent(event);
return false;
}
});
It solved the problem.But i can't understand this code.Can anyone help?
In your case, Scrollview
is parent whereas ListView
is its child.
So, in normal case when you try to scroll, the ScrollView
will intercept that event and the scroll of ScrollView
will occur. It will not reach the ListView
within as it is already handlled by the parent ScrollView
.
However, when you set a TouchListener
to the child ListView
and override its the onTouch()
as you have done, a different behaviour is observed.
case MotionEvent.ACTION_DOWN:
This event happens when the first finger is pressed onto the screen.
v.getParent().requestDisallowInterceptTouchEvent(true);
This will prevent the parent from intercepting the touch event, so that the child can handle the event appropriately.
case MotionEvent.ACTION_UP:
This event fires when all fingers are off the screen.
v.getParent().requestDisallowInterceptTouchEvent(false);
This will allow the parent to intercept the touch events thereafter, for rest of the screen leaving the childview.
Hope it helps you.