title: android change views on swipe
body: <p>I'm looking for a way to change the content of <code>TextViews</code> when the user swipes the layout holding those Views. My goal is something like that:
  <img src="https://i.stack.imgur.com/fG6Ck.jpg" alt="enter image description here"></p>
  
  <p>I'm trying to do this with a <code>SimpleOnGestureListener</code>(code goes below). The problem: when I swipe from left to right, the value of i becomes -1 and no reaction occures of following swipes. Right to left swipe causes i to become 1 (where the hell is zero?) and the View stops reacting on swipes again. What am I doing wrong?</p>
  
  <pre><code>     public class MainActivity extends Activity {
  private static final int SWIPE_MIN_DISTANCE = 120;
  private static final int SWIPE_MAX_OFF_PATH = 250;
  private static final int SWIPE_THRESHOLD_VELOCITY = 200;
  private GestureDetector gestureDetector;
  public View mainview;
  public TextView lol;
  
  @Override
  public void onCreate(Bundle savedInstanceState) {
      super.onCreate(savedInstanceState);
      setContentView(R.layout.activity_main);
  
      gestureDetector = new GestureDetector(new MyGestureDetector());
      mainview = (View) findViewById(R.id.mainView);
      lol = (TextView) findViewById(R.id.textView2);
  
      mainview.setOnTouchListener(new View.OnTouchListener() {
  
          public boolean onTouch(View v, MotionEvent event) {
              if (gestureDetector.onTouchEvent(event)) {
                  return true;
              }
              return false;
          }
      });
  }
  
  class MyGestureDetector extends SimpleOnGestureListener {
      @Override
      public boolean onFling(MotionEvent e1, MotionEvent e2, float velocityX,
              float velocityY) {
          int i = 0;
  
          if (Math.abs(e1.getY() - e2.getY()) &gt; SWIPE_MAX_OFF_PATH) {
              return false;
          }
  
          if (e1.getX() - e2.getX() &gt; SWIPE_MIN_DISTANCE
                  &amp;&amp; Math.abs(velocityX) &gt; SWIPE_THRESHOLD_VELOCITY) {
              i++;
              lol.setText("Text" + " " + Integer.toString(i));
  
              return true;
          } else if (e2.getX() - e1.getX() &gt; SWIPE_MIN_DISTANCE
                  &amp;&amp; Math.abs(velocityX) &gt; SWIPE_THRESHOLD_VELOCITY) {
              i--;
              lol.setText("Text" + " " + Integer.toString(i));
  
              return true;
          }
  
          return false;
      }
  
      @Override
      public boolean onDown(MotionEvent e) {
          return true;
      }
  }
      }
  </code></pre>