title: Android drawable swiping not working (from beginners sample code)
body: <p>I'm fluent in java for some years now but never tried making apps. So 2 days ago I started and it was just a 20 minute work from getting android studio over setting it up in netbeans to show a hello world app on my phone. But now i'm stuck with this approach for swiping through an array of jpg's. The app gets build and started, but not displaying any of my pics. Please have a look.</p>
  
  <pre><code>    package vf.base;
  
  import android.app.Activity;
  import android.content.res.TypedArray;
  import android.os.Bundle;
  import android.view.MotionEvent;
  import android.view.ViewGroup;
  import android.widget.ImageView;
  import android.widget.ViewFlipper;
  
  public class MainActivity extends Activity {
  
      private ViewFlipper viewFlipper;
      private TypedArray pics;
      private OnSwipeTouchListener onSwipeTouchListener;
  
      /**
       * Called when the activity is first created.
       */
      @Override
      protected void onCreate(Bundle savedInstanceState) {
          pics = getResources().obtainTypedArray(R.array.pics);
          super.onCreate(savedInstanceState);
          setContentView(R.layout.main);
  
          viewFlipper = (ViewFlipper) findViewById(R.id.viewFlipper);
          for (int i = 0; i &lt; pics.length(); i++) {
              AddViewFlipper(i);
          }
  
          onSwipeTouchListener = new OnSwipeTouchListener(this) {
              @Override
              public void onSwipeRight() {
                  viewFlipper.showNext();
              }
  
              @Override
              public void onSwipeLeft() {
                  viewFlipper.showPrevious();
              }
          };
  
          viewFlipper.setOnTouchListener(onSwipeTouchListener);
      }
  
      private void AddViewFlipper(int position) {
          ImageView imageView = new ImageView(MainActivity.this);
          imageView.setImageResource(position);
          ViewGroup.LayoutParams imageParams = new ViewGroup.LayoutParams(
                  ViewGroup.LayoutParams.MATCH_PARENT,            ViewGroup.LayoutParams.MATCH_PARENT);
          imageView.setLayoutParams(imageParams);
  
          viewFlipper.addView(imageView);
      }
  
      @Override
      public boolean dispatchTouchEvent(MotionEvent ev) {
          onSwipeTouchListener.gestureDetector.onTouchEvent(ev);
          return super.dispatchTouchEvent(ev);
      }
  }
  </code></pre>
  
  <p>.</p>
  
  <pre><code>    package vf.base;
  
  import android.content.Context;
  import android.view.GestureDetector;
  import android.view.MotionEvent;
  import android.view.View;
  
  public class OnSwipeTouchListener implements View.OnTouchListener {
      public GestureDetector gestureDetector;
  
      public OnSwipeTouchListener(Context context) {
          gestureDetector = new GestureDetector(context, new GestureListener());
      }
  
      public void onSwipeLeft() {
      }
  
      public void onSwipeRight() {
      }
  
      public boolean onTouch(View v, MotionEvent event) {
          return gestureDetector.onTouchEvent(event);
      }
  
      private final class GestureListener extends GestureDetector.SimpleOnGestureListener {
  
          private static final int SWIPE_DISTANCE_THRESHOLD = 100;
          private static final int SWIPE_VELOCITY_THRESHOLD = 100;
  
          @Override
          public boolean onDown(MotionEvent e) {
              return true;
          }
  
          @Override
          public boolean onFling(MotionEvent e1, MotionEvent e2, float velocityX, float velocityY) {
              float distanceX = e2.getX() - e1.getX();
              float distanceY = e2.getY() - e1.getY();
              if (Math.abs(distanceX) &gt; Math.abs(distanceY) &amp;&amp; Math.abs(distanceX) &gt; SWIPE_DISTANCE_THRESHOLD
                      &amp;&amp; Math.abs(velocityX) &gt; SWIPE_VELOCITY_THRESHOLD) {
                  if (distanceX &gt; 0)
                      onSwipeRight();
                  else
                      onSwipeLeft();
                  return true;
              }
              return false;
          }
  
      }
  }
  </code></pre>
  
  <p>.</p>
  
  <pre><code>    &lt;?xml version="1.0" encoding="UTF-8"?&gt;
  &lt;resources&gt;
  &lt;integer-array name="pics"&gt;
      &lt;item&gt;@drawable/tp_001&lt;/item&gt;
      &lt;item&gt;@drawable/tp_002&lt;/item&gt;
      &lt;item&gt;@drawable/tp_003&lt;/item&gt;
  
  &lt;/integer-array&gt;
  &lt;/resources&gt;
  </code></pre>
  
  <p>Thanks!</p>
  
  <p>EDIT: Layout.xml</p>
  
  <pre><code>    &lt;?xml version="1.0" encoding="utf-8"?&gt;
  &lt;LinearLayout
      xmlns:android="http://schemas.android.com/apk/res/android"
      android:layout_width="fill_parent"
      android:layout_height="fill_parent"
      android:orientation="vertical"&gt;
  
      &lt;ViewFlipper
          android:layout_width="fill_parent"
          android:layout_height="fill_parent"
          android:id="@+id/viewFlipper"
          android:layout_alignParentTop="true"
          android:layout_alignParentStart="true" /&gt;
  
  &lt;/LinearLayout&gt;
  </code></pre>