简体   繁体   English

Android,GridView和onTouchListener

[英]Android, GridView and onTouchListener

My application have three pages (three tabs) and I want to switch beetween two gridviews by moving finger horizontaly. 我的应用程序有三个页面(三个选项卡),我想通过水平移动手指在两个gridview之间切换。 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. 我使用方法onItemClickListener(onClickListener在Gridview上不起作用),但是未单击网格项。 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? 该onTouch代码在什么视图中? 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. 您可以尝试将最后一个return true更改为return false以便如果该动作不是运动事件,则视图不会使用该事件。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM