简体   繁体   中英

Android, GridView and onTouchListener

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.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

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