我有以下布局
<ViewSwitcher>
<LinearLayout>
<ListView />
</LinearLayout>
<LinearLayout>
<ListView />
</LinearLayout>
</ViewSwitcher>
但是当我切换 ViewSwitcher(通过 onTouchListener)时,我的布局中 ListView 的 onItemClickListener 也会响应。我在切换时不需要那个。如何解决?
这是我的切换器类:
public class MMGViewSwitcher extends ViewSwitcher{
private float startX = 0;
private float startY = 0;
private float endX = 0;
private float endY = 0;
public MMGViewSwitcher(Context context, AttributeSet attrs) {
super(context,attrs);
}
@Override
public boolean onTouchEvent(MotionEvent event)
{
String ActionString="";
switch(event.getActionMasked())
{
case MotionEvent.ACTION_DOWN:
startX = event.getX();
startY = event.getY();
ActionString="ACTION_DOWN";
break;
case MotionEvent.ACTION_MOVE:
ActionString="ACTION_MOVE";
break;
case MotionEvent.EDGE_LEFT:
this.showNext();
break;
case MotionEvent.EDGE_RIGHT:
this.showPrevious();
break;
case MotionEvent.ACTION_UP:
endX = event.getX();
endY = event.getY();
if((startX > endX) && Math.abs(startX-endX)>30){
this.showNext();
}
if((startX < endX) && Math.abs(startX-endX)>30){
this.showPrevious();
}
ActionString="ACTION_UP";
break;
}
return true;
}
@Override
public boolean onInterceptTouchEvent(MotionEvent ev)
{
onTouchEvent(ev);
return false;
}
}