title: Android how to make Gallery auto scroll to first item?
body: <p>I followed this topic <a href="https://stackoverflow.com/questions/8155245/auto-scroll-a-gallery-widget">auto scroll a Gallery widget</a> to create a Gallery auto scroll from left to right every 5 seconds. Here's my Gallery:</p>
  
  <pre><code>public class MyBannersGallery extends Gallery {
  
  private Handler handler;
  
  public MyBannersGallery(Context ctx, AttributeSet attrSet) {
      super(ctx, attrSet);
      handler = new Handler();
      postDelayedScrollNext();
  }
  
  private void postDelayedScrollNext() {
      handler.postDelayed(new Runnable() {
          public void run() {
              postDelayedScrollNext();
              onKeyDown(KeyEvent.KEYCODE_DPAD_RIGHT, null);
          }
      }, 5000);
  
  }
  
  private boolean isScrollingLeft(MotionEvent e1, MotionEvent e2) {
      return e2.getX() &gt; e1.getX();
  }
  
  public boolean onFling(MotionEvent e1, MotionEvent e2, float velocityX,
          float velocityY) {
      int kEvent;
      if (isScrollingLeft(e1, e2)) {
          kEvent = KeyEvent.KEYCODE_DPAD_LEFT;
      } else {
          kEvent = KeyEvent.KEYCODE_DPAD_RIGHT;
      }
      onKeyDown(kEvent, null);
      return true;
  }
  </code></pre>
  
  <p>}</p>
  
  <p>When it scrolled to the end of my Gallery, it stopped. Now I want to detect if my Gallery is scrolled to the end or not. And if it does, scroll back to the left to the first item. What should I edit my class to archive this?</p>