Android, GridView and onTouchListener

落花浮王杯 提交于 2019-12-08 12:43:22

问题


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;
}

回答1:


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.



来源:https://stackoverflow.com/questions/3335211/android-gridview-and-ontouchlistener

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!