title: Prevent Gallery from Scrolling on Item Selection
body: <p>How can I prevent a <code>Gallery</code> from scrolling when an item is selected?<br>
  <code>OnItemClickListener</code> has so far been unsuccessful for me.</p>
  
  <pre><code>gal.setOnItemClickListener(new OnItemClickListener() 
  {
      public void onItemClick(AdapterView parent, View v, int position, long id) 
  {
           ((ImageGallery) parent).setScrollingEnabled(false);
  }
  });
  </code></pre>
  
  <p>I have subclassed <code>Gallery</code>:</p>
  
  <pre><code>public class ImageGallery extends Gallery
  {
    private boolean stuck = false;
  
    public ImageGallery(Context context, AttributeSet attrs, int defStyle) {
      super(context, attrs, defStyle);
    }
  
    public ImageGallery(Context context, AttributeSet attrs) {
      super(context, attrs);
    }
  
    public ImageGallery(Context context) {
      super(context);
    }
  
    @Override
    public boolean onTouchEvent(MotionEvent event) 
    {
      return stuck || super.onTouchEvent(event);
    }
  
    @Override
    public boolean onKeyDown(int keyCode, KeyEvent event) {
      switch (keyCode) {
      case KeyEvent.KEYCODE_DPAD_LEFT:
      case KeyEvent.KEYCODE_DPAD_RIGHT:
        return stuck || super.onKeyDown(keyCode, event);
      }
      return super.onKeyDown(keyCode, event);
    }
  
    public void setScrollingEnabled(boolean enabled) 
    {
      stuck = !enabled;
    }
  }
  </code></pre>