32

I have added a bunch of images to a ViewFlipper and now I am performing an onClick event in the flipper. For this I would like to know the current child position so that I can perform some operations in an array. Is there anyway to find out the position of the current child.

Andro Selva
  • 53,910
  • 52
  • 193
  • 240

4 Answers4

61

Use this to get the current Child position:

flipper.getDisplayedChild();

And this to set child number to view:

flipper.setDisplayedChild(8);
Jonathan Day
  • 18,519
  • 10
  • 84
  • 137
Awais Tariq
  • 7,724
  • 5
  • 31
  • 54
3

In addflipperimages(ViewFlipper flipper) method you are adding bunch of images to ViewFlipper for that you are creating imageview, set tag to imageview, set imageview clickable true then write onclick method to imageview. go through the fallowing code it may works for you
here ids[] is an array of image ids

private void addFlipperImages(ViewFlipper flipper) {

        int imageCount = ids.length;
    RelativeLayout.LayoutParams params = new RelativeLayout.LayoutParams(
            RelativeLayout.LayoutParams.FILL_PARENT,
            RelativeLayout.LayoutParams.FILL_PARENT);

    for (int count = 0; count <imageCount; count++) {
        ImageView imageView = new ImageView(this);
        Bitmap imbm = BitmapFactory.decodeResource(this.getResources(),ids[count]);          
        imageView.setImageBitmap(imbm);

        imageView.setLayoutParams(params);
        imageView.setTag(count);
        imageView.setClickable(true);

        imageView.setOnClickListener(new OnClickListener() {

            public void onClick(View v) {
                // TODO Auto-generated method stub
                int id=(Integer) v.getTag();
                Toast.makeText(ImageSliderVertical.this, id+"", Toast.LENGTH_LONG).show();

            }
        });
        flipper.addView(imageView);
        flipper.setTag(count);

                  }

}
Ankur
  • 5,086
  • 19
  • 37
  • 62
sowjanya
  • 31
  • 1
1

I used this flipper.indexOfChild(flipper.getCurrentView())

Andro Selva
  • 53,910
  • 52
  • 193
  • 240
1

Make use of indexOfChild().

Check this Post

How can I programmatically display a ViewFlipper's second child?

May this works for you.

Community
  • 1
  • 1
Last Warrior
  • 1,307
  • 1
  • 11
  • 20