我的应用程序中有三个页面(三个选项卡),我想通过horizontaly移动手指beetween 2 GridView的切换。触摸code工作正常,但我不能再点击网格上的物品!我使用的方法onItemClickListener(onClickListener不工作在GridView的),但电网项目不点击。感谢您的帮助!
在code是:
myGrid.setOnTouchListener(本);myGrid.setOnItemClickListener(本);....公共布尔onTouch(视图V,MotionEvent事件){ INT eventaction = event.getAction(); 开关(eventaction){ 案例MotionEvent.ACTION_DOWN: XSTART = event.getX(); 打破; 案例MotionEvent.ACTION_UP: XEND = event.getX(); 如果(XEND - XSTART→20){ //切换到previous标签 } 如果(XEND - XSTART< -20){ //切换到下一个标签 } 返回true; 默认: 打破; } 返回true;}
解决方案
什么观点是,onTouch code吗?你可以尝试改变,去年返回true
到返回false
因此,如果动作不是motionevent,事件不受视图消耗
My application have three pages (three tabs) and I want to switch beetween two gridviews by moving finger horizontaly. The touch code works fine but I can't click anymore on the grid items! I use the method onItemClickListener (onClickListener don't works on Gridview) but the grid item is not clicked. Thanks for your help!
The code is :
myGrid.setOnTouchListener(this);
myGrid.setOnItemClickListener(this);
....
public boolean onTouch(View v, MotionEvent event) {
int eventaction = event.getAction();
switch (eventaction) {
case MotionEvent.ACTION_DOWN:
xStart = event.getX();
break;
case MotionEvent.ACTION_UP:
xEnd = event.getX();
if (xEnd - xStart > 20){
//switch to previous tab
}
if (xEnd - xStart < -20){
//switch to next tab
}
return true;
default:
break;
}
return true;
}
解决方案
What view is that onTouch code in? You could try changing that last return true
to return false
so that if the action wasn't a motionevent, the event is not consumed by the view.
上一篇:CaptureFromFile在OpenCV的Android上使用JavaOpenCV、CaptureFromFile、Andr、Java
下一篇:我如何使用OnItemClickListener基础上被点击该项目,将启动一个新的意图是什么?基础上、该项目、如何使用、意图