Viewflipper Dinamico - Android

Asked

Viewed 241 times

2

Hello, I need to create a dynamic viewFlipper with 12 Imagesview or when loading Activity I need this Flipper to upload the images for me. Below is my code:

In XML

    <ViewFlipper
    android:id="@+id/rflipper"
    android:layout_width="wrap_content"
    android:layout_height="120dp"
    android:gravity="center"
    android:layout_gravity="top"
    android:autoStart="false"
    android:background="#f5f5f5"
    android:layout_marginRight="5dp"
    android:layout_marginLeft="5dp"
    android:visibility="visible">
    </ViewFlipper>

in Activity

    public void onCreate(Bundle savedInstanceState) {
      super.onCreate(savedInstanceState);
      setContentView(R.layout.activity_resultado);
      int images[] = R.drawable.imv1, R.drawable.imv2, R.drawable.imv3, R.drawable.imv4, R.drawable.imv5, R.drawable.imv6, R.drawable.imv7, R.drawable.imv8, R.drawable.imv9, R.drawable.imv10, R.drawable.imv11, R.drawable.imv12};
      vFlipper = (ViewFlipper) findViewById(R.id.rflipper);
      vFlipper.setInAnimation(this, android.R.anim.fade_in);
      vFlipper.setOutAnimation(this, android.R.anim.fade_out);
      for(int i=0;i<images.length;i++)
      {
        setFlipperImage(images[i]);
      }
      vFlipper.setAutoStart(true);
      vFlipper.setFlipInterval(4000);
      vFlipper.showNext();
    }
    private void setFlipperImage(int res) {
      Log.i("Set Filpper add", res+"");
      ImageView image = new ImageView(getApplicationContext());
      image.setBackgroundResource(res);
      vFlipper.addView(image);
    }

When I test this code does not present any error just does not show Flipper consequently does not show the images. I’m guessing it’s a lack of showing some view or Flipper show to show him, but I don’t know how to do that. Thanks in advance.

  • Try eliminating the line vFlipper.setAutoStart(true); and replace vFlipper.showNext(); for vFlipper.startFlipping()

  • ramaral: it worked was that very thank you!

No answers

Browser other questions tagged

You are not signed in. Login or sign up in order to post.