title: Android viewflipper and gallery
body: <p>I am trying to develop a application which contain a gallery with view flipper.</p>
  
  <p>Gallery shows all the images.What I want to do is, the image which is shown in the view flipper should be highlighted in the gallery.</p>
  
  <p>Currently I am able to highlight it on onClick.But not able to make communication between both.</p>
  
  <p>I tried using following method</p>
  
  <pre><code>viewflipper.getDisplayedChild();
  </code></pre>
  
  <p>but it doesn't work.</p>
  
  <p>following is my code</p>
  
  <pre><code>public class SliderActivity extends Activity 
  {
  int mFlipping = 0 ;
  public int currentimageindex=0;
  Timer timer;
  TimerTask task;
  ImageView slidingimage;
  android.widget.ViewFlipper flipper;
  Gallery gallery;
  
  
  private int[] IMAGE_IDS = 
  {
      R.drawable.android0, R.drawable.android1,           R.drawable.android2,R.drawable.android3,R.drawable.android4
  };
  
  
  
  @Override
  public void onCreate(Bundle savedInstanceState) 
  {
      super.onCreate(savedInstanceState);
      setContentView(R.layout.mygame);
      flipper = (android.widget.ViewFlipper) findViewById(R.id.flipper1);
  
      for(int i=0;i&lt;IMAGE_IDS.length;i++)
      {
      //  This will create dynamic image view and add them to ViewFlipper
          ImageView image = new ImageView(getApplicationContext());
          image.setBackgroundResource(IMAGE_IDS[i]);
          flipper.addView(image);
      }
  
  
      gallery=(Gallery)findViewById(R.id.gallery1);
      gallery.setAdapter(new ImageAdapter(this));
  
      if(mFlipping==0){
          /** Start Flipping */
          flipper.startFlipping();
          mFlipping=1;
          //mButton.setText(R.string.str_btn_stop);
      }
      else{
          /** Stop Flipping */
          flipper.stopFlipping();     
          mFlipping=0;
      //  mButton.setText(R.string.str_btn_start);
      }
  
  }
  
  
  public class ImageAdapter extends BaseAdapter 
  {
         int mGalleryItemBackground;
         private Context mContext;
  
         public ImageAdapter(Context c) 
         {
             mContext = c;
             TypedArray a = obtainStyledAttributes(R.styleable.Theme);
             mGalleryItemBackground = a.getResourceId(
               R.styleable.Theme_android_galleryItemBackground,0);
             a.recycle();
         }
  
         public int getCount() 
         {
             return IMAGE_IDS.length;
         }
  
         public Object getItem(int position) 
         {
  
             return position;
         }
  
         public long getItemId(int position) 
         {
             return position;
  
  
         }
  
         public View getView(int position,View convertView, ViewGroup parent) 
         {
             ImageView i = new ImageView(mContext);
             i.setImageResource(IMAGE_IDS[position]);
             i.setLayoutParams(new Gallery.LayoutParams(150, 100));
             i.setScaleType(ImageView.ScaleType.FIT_XY);
             i.setBackgroundResource(mGalleryItemBackground);
  
             return i;
         }
      }
  
  public void onClick(View v) {
  
      finish();
      android.os.Process.killProcess(android.os.Process.myPid());
    }
  </code></pre>
  
  <p>}</p>