How to disable scrolling in GridView?

好久不见. 提交于 2020-01-04 06:03:20

问题


My application has a GridView. It already has a onItemClickListener and onItemLongClickListener. I would like to disable the scrolling in the GridView now. With the help of https://stackoverflow.com/a/6496632/985025 I have added an onTouchListener as shown below:

        mGridView.setOnItemClickListener(this);  
        mGridView.setOnItemLongClickListener(this);  
        mGridView.setOnTouchListener(new OnTouchListener(){  
            @Override  
            public boolean onTouch(View arg0, MotionEvent arg1) {  
                if(arg1.getAction() == MotionEvent.ACTION_MOVE)  
                    return true;  
                else  
                    return false;  
            }  
        });  

My expected behavior is that when ever I try to scroll in the GridView, that event should be ignored. But, I get an event in onItemClick even after returning true in onTouch. Is there a way to avoid onItemClick in case of scroll on GridView?


回答1:


Use a TableLayout. Achieves exactly what you want. A GridView is a super overkill in your use case with all its recycling.




回答2:


Folks here have engulfed the GridView with a ScrollView and that did the trick, I hope it helps anyone who is stuck with this problem.



来源:https://stackoverflow.com/questions/8908228/how-to-disable-scrolling-in-gridview

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