开发者

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.

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜