title: Android Gallery control - need infinite loop of images
body: <p>Without starting from the middle of the stack of images how do I rotate them in the infinite loop left to right and right to left? I tried setSelection(position) but for some reason I get that method called few times and inconsistently. My images increment has to be saved int he app state so it makes it a bit more complicated.</p>
  
  <pre><code>@Override
      public void setSelection(int position){
  
          int sectionPos = getCurrentPositionFromState();
  
          if (sectionPos == (this._images - 1)){  
              setCurrentPositionFromState(0);
              sectionPos = 0;
          }
          else {
              setCurrentPositionInState(sectionPos +1);
          }
          if (sectionPos &lt;= (this._images - 1) ){
              super.setSelection(sectionPos);
          }
      }
  
  gallery.setOnItemSelectedListener(new OnItemSelectedListener() {     
              @Override
              public void onItemSelected(AdapterView parent, View view, int position, long id) {
  
                  gallery.setSelection(position);
  
  
              @Override
              public void onNothingSelected(AdapterView parent) {
  
  
              }
          });
  </code></pre>
  
  <p>I should also mention that I have an onFling() overriden like so:</p>
  
  <pre><code>@Override
         public boolean onFling(MotionEvent e1, MotionEvent e2, float velocityX, float velocityY) {
           return super.onFling(e1, e2, 0, velocityY);
         }
  </code></pre>