user838522
user838522

Reputation: 3991

regarding viewflipper with auto-flipping

Right now I'm able flip views using sliding. I want to flip views automatically after say 5 seconds.

The code I have to flip views based on gesture recognition is:

class MyGestureDetector extends SimpleOnGestureListener {
    @Override
    public boolean onFling(MotionEvent e1, MotionEvent e2, float velocityX,
            float velocityY) {
        try {
            if (Math.abs(e1.getY() - e2.getY()) > SWIPE_MAX_OFF_PATH)
                return false;
            // right to left swipe
            if (e1.getX() - e2.getX() > SWIPE_MIN_DISTANCE
                    && Math.abs(velocityX) > SWIPE_THRESHOLD_VELOCITY) {
                viewFlipper.setInAnimation(slideLeftIn);
                viewFlipper.setOutAnimation(slideLeftOut);

                if (currentIndex == maxIndex) {
                    currentIndex = 0;
                } else {
                    currentIndex = currentIndex + 1;
                }
                if (currentView == 0) {
                    currentView = 1;
                    ImageView iv = (ImageView) findViewById(R.id.one);
                    /*iv.setImageDrawable(Drawable.createFromPath(ImageList
                            .get(currentIndex)));*/
                    Bitmap mBitmap=BitmapFactory.decodeFile(ImageList.get(currentIndex));
                    iv.setImageBitmap(mBitmap);
                    Log.d("image list index!!", ImageList.get(currentIndex));
                    System.gc();

                } else if (currentView == 1) {
                    currentView = 2;
                    ImageView iv = (ImageView) findViewById(R.id.two);
                    /*iv.setImageDrawable(Drawable.createFromPath(ImageList
                            .get(currentIndex)));*/
                    Bitmap mBitmap=BitmapFactory.decodeFile(ImageList.get(currentIndex));
                    iv.setImageBitmap(mBitmap);
                    Log.d("image list index!!", ImageList.get(currentIndex));

                    System.gc();
                } else {
                    currentView = 0;
                    ImageView iv = (ImageView) findViewById(R.id.zero);
                    /*iv.setImageDrawable(Drawable.createFromPath(ImageList
                            .get(currentIndex)));
                    */
                    Bitmap mBitmap=BitmapFactory.decodeFile(ImageList.get(currentIndex));
                    iv.setImageBitmap(mBitmap);
                    Log.d("image list index!!", ImageList.get(currentIndex));

                    System.gc();
                }
                Log.v("ImageViewFlipper", "Current View: " + currentView);
                viewFlipper.showNext();
                viewFlipper.startFlipping();
            } else if (e2.getX() - e1.getX() > SWIPE_MIN_DISTANCE
                    && Math.abs(velocityX) > SWIPE_THRESHOLD_VELOCITY) {
                viewFlipper.setInAnimation(slideRightIn);
                viewFlipper.setOutAnimation(slideRightOut);
                if (currentIndex == 0) {
                    currentIndex = maxIndex;
                } else {
                    currentIndex = currentIndex - 1;
                }
                if (currentView == 0) {
                    currentView = 2;
                    ImageView iv = (ImageView) findViewById(R.id.two);
                    iv.setImageDrawable(Drawable.createFromPath(ImageList
                            .get(currentIndex)));
                    System.gc();
                } else if (currentView == 2) {
                    currentView = 1;
                    ImageView iv = (ImageView) findViewById(R.id.one);
                    iv.setImageDrawable(Drawable.createFromPath(ImageList
                            .get(currentIndex)));
                    System.gc();
                } else {
                    currentView = 0;
                    ImageView iv = (ImageView) findViewById(R.id.zero);
                    iv.setImageDrawable(Drawable.createFromPath(ImageList
                            .get(currentIndex)));
                    System.gc();
                }
                Log.v("ImageViewFlipper", "Current View: " + currentView);
                viewFlipper.showPrevious();
            }
        } catch (Exception e) {
            // nothing
        }
        return false;

    }

}

I am flipping using viewFlipper.showNext() and showPrevious() methods now. I tried using

       viewFlipper.setFlipInterval(1000);

and viewFlipper.startFlipping(); methods. The problem I am facing now is there are 3 imageviews I need to load one after the other in a row continuously (and images should change in each of the imageviews as they move on). This is not happening. I can see only 2 fixed images just displaying one after the other without any change in their content. How do I solve this issue?

Upvotes: 0

Views: 4881

Answers (1)

drooooooid
drooooooid

Reputation: 1584

have a look at startFlipping() and setFlipInterval() methods in ViewFlipper class

http://android-er.blogspot.com/2011/03/auto-flipping-of-viewflipper.html

follow the above link.hope it helps

Upvotes: 2

Related Questions