title: fullscreen ImageSwitcher without gallery in Android
body: <p>I'm trying to build an application in android, in one of my activities I wanna show full screen images and make them slide left and right by sliding finger on the pictures.</p>
  
  <p>I have tried basic gallery view and Image Switcher but I couldn't handle the touch event to have a sliding effect as like in custom android gallery but without thumbnails.</p>
  
  <p>Here is my simple image switcher xml and activity class. I would be very appreciated if anybody shows me a way or edits my code below.
  Thanks in advance...</p>
  
  <p>layout xml: </p>
  
  <pre><code> &lt;?xml version="1.0" encoding="utf-8"?&gt;
      &lt;ImageSwitcher 
      xmlns:android="http://schemas.android.com/apk/res/android"
      android:id="@+id/imageSwitcher"
      android:layout_width="fill_parent"
      android:layout_height="fill_parent"
      android:layout_alignParentBottom="true"
      android:layout_alignParentLeft="true"
      android:layout_alignParentTop="true"
      android:onClick="imageClick"
      android:src="@drawable/ic_launcher"
      android:keepScreenOn="true"&gt;
      &lt;/ImageSwitcher&gt;
  </code></pre>
  
  <p>code :</p>
  
  <pre><code>public class GalleryActivity extends Activity implements ViewFactory {
  
      private ImageSwitcher imageSwitcher ;
  
  
      @Override  
      public void onCreate(Bundle savedInstanceState) {  
           super.onCreate(savedInstanceState);  
           setContentView(R.layout.activities);  
  
           imageSwitcher = (ImageSwitcher) findViewById(R.id.imageSwitcher);
           imageSwitcher.setFactory(this);
           imageSwitcher.setInAnimation(AnimationUtils.loadAnimation(this, android.R.anim.fade_in));
           imageSwitcher.setOutAnimation(AnimationUtils.loadAnimation(this, android.R.anim.fade_out));
  
           imageSwitcher.setImageResource(R.drawable.menu);
  
           imageSwitcher.setOnTouchListener(new OnTouchListener() {
  
              public boolean onTouch(View v, MotionEvent event) {
                  findViewById(R.drawable.menu);
                  imageSwitcher.addView((ImageSwitcher) findViewById(R.drawable.etkinlik));
                  imageSwitcher.showNext();
  
                  return false;
              }
          });
      }  
          public View makeView() {  
          ImageView iView = new ImageView(this);
          iView.setScaleType(ImageView.ScaleType.FIT_CENTER);
          iView.setLayoutParams(new
                      ImageSwitcher.LayoutParams(
                                  LayoutParams.FILL_PARENT,LayoutParams.FILL_PARENT));
          iView.setBackgroundColor(0xFF000000);
          return iView;
      }
  }  
  </code></pre>
  
  <p>After editing a bit of  @imran khan 's solution , here is the code which works quite well.</p>
  
  <p>SOLUTION:</p>
  
  <pre><code>ImageSwitcher imageSwitcher ;
  
  Integer[] imageList = {
          R.drawable.gallery,
          R.drawable.menu,
          R.drawable.promotion,
          R.drawable.info,
          R.drawable.activities       
  };
  
  int curIndex=0;
  int downX,upX;
  
  @Override  
  public void onCreate(Bundle savedInstanceState) {
       super.onCreate(savedInstanceState);  
       setContentView(R.layout.activities);  
  
       imageSwitcher = (ImageSwitcher) findViewById(R.id.imageSwitcher);
       imageSwitcher.setFactory(this);
       imageSwitcher.setInAnimation(AnimationUtils.loadAnimation(this,android.R.anim.fade_in));
       imageSwitcher.setOutAnimation(AnimationUtils.loadAnimation(this,android.R.anim.fade_out));
  
       imageSwitcher.setImageResource(imageList[curIndex]);
       imageSwitcher.setOnTouchListener(new OnTouchListener() {
       @Override
       public boolean onTouch(View v, MotionEvent event) {
  
           if (event.getAction() == MotionEvent.ACTION_DOWN) {
               downX = (int) event.getX(); 
               Log.i("event.getX()", " downX " + downX);
               return true;
           } 
  
           else if (event.getAction() == MotionEvent.ACTION_UP) {
               upX = (int) event.getX(); 
               Log.i("event.getX()", " upX " + downX);
               if (upX - downX &gt; 100) {
  
                   //curIndex  current image index in array viewed by user
                   curIndex--;
                   if (curIndex &lt; 0) {
                       curIndex = imageList.length-1;
                   }
  
                   imageSwitcher.setInAnimation(AnimationUtils.loadAnimation(GalleryActivity.this,R.anim.slide_in_left));
                   imageSwitcher.setOutAnimation(AnimationUtils.loadAnimation(GalleryActivity.this,R.anim.slide_out_right));
  
                   imageSwitcher.setImageResource(imageList[curIndex]);
                   //GalleryActivity.this.setTitle(curIndex);
               } 
  
               else if (downX - upX &gt; -100) {
  
                   curIndex++;
                   if (curIndex &gt; 4) {
                       curIndex = 0;
                   }
  
                   imageSwitcher.setInAnimation(AnimationUtils.loadAnimation(GalleryActivity.this,R.anim.slide_in_right));
                   imageSwitcher.setOutAnimation(AnimationUtils.loadAnimation(GalleryActivity.this,R.anim.slide_out_left));
  
                   imageSwitcher.setImageResource(imageList[curIndex]);
                   //GalleryActivity.this.setTitle(curIndex);
               }
                   return true;
               }
               return false;
           }
       });
  }
  @Override
  public View makeView() {
      ImageView i = new ImageView(this);  
      i.setScaleType(ImageView.ScaleType.FIT_CENTER);
      return i;
  }
  </code></pre>