2

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?

Community
  • 1
  • 1
Rc N
  • 103
  • 3
  • 6
  • Possible duplicate of [How to disable GridView scrolling in Android?](http://stackoverflow.com/questions/4852867/how-to-disable-gridview-scrolling-in-android) – lxknvlk Oct 23 '16 at 12:23
  • You can check here. [view](https://stackoverflow.com/questions/4852867/how-to-disable-gridview-scrolling-in-android), maybe It's work – Cuong Nguyen Oct 18 '18 at 03:52

2 Answers2

1

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

Vikram Bodicherla
  • 7,133
  • 4
  • 28
  • 34
0

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.

Rc N
  • 103
  • 3
  • 6
  • Oh please don't do that! This is bad for performance (How should the `GridView` guess its size? So it will create much more controls as really needed) and if th grid view does not consume the hole space of the `ScrollView` which of the both views should scroll? The `GridView` or the `ScrollView` or both? – rekire Apr 25 '13 at 07:12