Issue
I have a ListView with com.google.android.gms.maps.MapView in its header. When I'm scrolling the list I want the MapView to be hidden and it works just fine. But, when I'm scrolling the header from up to down, or down up I don't want ListView to perform scrolling - I want it to allow MapView to perform its zoom/scroll operations.
I know that it's bad idea to use ListView/MapView together, but I need to find a solution. I thought about setting the OnTouchListener on the ListView instance and dispatching its events to the MapView when needed but it looks like a not very straightforward solution.
Solution
In the end I've solved it by extending the ListView class:
public class SingleScrollableHeaderListView extends ListView {
private View mHeaderView;
public SingleScrollableHeaderListView(Context context) {
super(context);
}
public SingleScrollableHeaderListView(Context context, AttributeSet attrs) {
super(context, attrs);
}
public SingleScrollableHeaderListView(Context context, AttributeSet attrs, int defStyle) {
super(context, attrs, defStyle);
}
@Override
public boolean onInterceptTouchEvent(MotionEvent ev) {
if (mHeaderView != null) return mHeaderView.onTouchEvent(ev);
return super.onInterceptTouchEvent(ev);
}
@Override
public void addHeaderView(View v, Object data, boolean isSelectable) {
if (mHeaderView != null) removeHeaderView(mHeaderView);
mHeaderView = v;
super.addHeaderView(v, data, isSelectable);
}
}
The significant part is the onInterceptTouchEvent() method - here I'm passing the MotionEvent instance to the header view if it exists, otherwise I let the ListView to deal with the motion event.
Answered By - aga
0 comments:
Post a Comment
Note: Only a member of this blog may post a comment.