0

enter image description hereenter image description here

I am using AnimationDrawable to create a Frame by Frame effect, I want to when the images changes, the circle dot change together, my code create a infinite loop, if I get off While(mframeAnimation.isRunning()) then it just check the value one time and stop.

Question:

So what should I do to create an infinite check, a listener or something like that to change the circle when image changes?

 private void selectDot(int arg2) {
            // TODO Auto-generated method stub
            for(int i=0;i<imageView.length;i++){
              if(i==arg2) imageView[i].setImageResource(R.drawable.black_circle);
              else imageView[i].setImageResource(R.drawable.gray_circle);
             }
        }

        class Starter implements Runnable {
            public void run() {
                mframeAnimation.start();
                while(mframeAnimation.isRunning()){
                    // Get the frame of the animation
                    Drawable currentFrame, checkFrame;
                    currentFrame = mframeAnimation.getCurrent();

                    int frameNumber;
                    // Checks the position of the frame
                    for (int i = 0; i < mframeAnimation.getNumberOfFrames(); i++) {
                        checkFrame = mframeAnimation.getFrame(i);
                        if (checkFrame == currentFrame) {
                            frameNumber = i;
    //                      Toast.makeText(getActivity(), Integer.toString(frameNumber), Toast.LENGTH_SHORT).show();
                            selectDot(frameNumber);
                            break;
                        }
                    }
                    }
            }
    }
Marckaraujo
  • 7,422
  • 11
  • 59
  • 97
  • and your question is? Usually it helps to point out what you expect and what actually happens – Emile Vrijdags Jan 13 '13 at 23:43
  • I think it was clear, but I edited, thanks – Marckaraujo Jan 13 '13 at 23:46
  • 1
    @Marckaraujo I did a much similar carousel for advertising also, i started doing it as you are doing it then discovered that ViewFlipper is much better and way faster to use , and it has build in animator through all the images provided, let me know if you need anymore info i can provide you some code. – N Jay Jan 13 '13 at 23:49
  • 1
    @NaderAyyad, Wow man you saved my life, I just saw a very simple example and it is what I need, if you could provide me some code, thanks – Marckaraujo Jan 14 '13 at 00:00

1 Answers1

1

This the ViewFlipper that i applied tp get my carousel effect, i tweaked the animation a bit to make it fit what i want exactly. So yes ViewFlipper is your answer.

N Jay
  • 1,774
  • 1
  • 17
  • 36
  • DO you know what listener I should use for this? – Marckaraujo Jan 14 '13 at 14:21
  • @Marckaraujo why is it not working whats your problem?? let me know how can i help?? i have already implemented my carousel and it works liek a charm – N Jay Jan 14 '13 at 15:28
  • Well, see the picture, the animation with the picture goes well it changes correct, I am trying to get the id from the current image showing and use it to select the dot image, but I think its not possible, I just think that I need to create a dot image together with the picture, correct? – Marckaraujo Jan 14 '13 at 21:06
  • @Marckaraujo are the images dynamic??? or you know the number of image ur gana show? – N Jay Jan 14 '13 at 22:17
  • Well, I put it to work, I just created a LinearLayout with Image and dotImage inside ViewFlipper, the only problem is that you need to create a lot of Imageview with the dotImage. – Marckaraujo Jan 15 '13 at 11:32