Search code examples
javaandroidviewflipper

To display a button only for the last Flipper image in Viewflipper


In my app i have one Viewflipper in which four images will be loaded from array in programmatically. But only for the Last flipper image i need to display a go button.

<ViewFlipper
    android:id="@+id/view_flipper"
    android:layout_width="fill_parent"
    android:layout_height="fill_parent" >
</ViewFlipper>

<Button
    android:id="@+id/gotoapp"
    android:layout_width="wrap_content"
    android:layout_height="wrap_content"
    android:text="go"
    android:visibility="gone"/>

In java:

int gallery_grid_Images[]={R.drawable.splash1,R.drawable.splash2,R.drawable.splash3,R.drawable.splash4};
mViewFlipper = (ViewFlipper) this.findViewById(R.id.view_flipper);
for(int i=0;i<gallery_grid_Images.length;i++)
    {
        setFlipperImage(gallery_grid_Images[i]);
    }

For setflipperImage() method:

     private void setFlipperImage(int res) {
       ImageView image = new ImageView(getApplicationContext());
       image.setBackgroundResource(res);
       mViewFlipper.addView(image);
     }

So please help me how to visible/show the "Go" button for only last flipper image(4th image)


Solution

  • Use this to get the current Child position:

    flipper.getDisplayedChild();
    

    And this to set child number to view:

    flipper.setDisplayedChild(4);
    

    Add an animation listener to the animation object you set as the viewflipper's 'IN' animation. Overide the listeners onAnimationEnd method, and inside that method check

     if(flipper.getDisplayedChild() == 4)
          visible your GO Button
         else 
          hide your button