How do you use the setAnimationListener to delay a while loop so that each pass the animation completes before the next loop?
<p>Using the example <a href="http://www.codeshogun.com/blog/2009/04/16/how-to-implement-swipe-action-in-android/" rel="nofollow"> <strong>codeshogun</strong> </a> has posted for the swipesample I have changed the code to infalte the layout with extra colored text boxes (Yellow,Red,Blue,Green,Black,Gray,White). These extra TextViews will be generated by xml down the track.</p>

<p>To create the TextView I use the following code:</p>

<pre><code>    //Create a layout with a solid blue background programmatically
    TextView tvY = new TextView(this);
    tvY.setText("Yellow");
    tvY.setBackgroundColor(Color.YELLOW);
    tvY.setLayoutParams(new LayoutParams(LayoutParams.FILL_PARENT, LayoutParams.FILL_PARENT));

    LinearLayout llY = new LinearLayout(this);
    llY = new LinearLayout(this);
    llY.setOrientation(LinearLayout.VERTICAL);
    llY.setLayoutParams(new LayoutParams(LayoutParams.FILL_PARENT, LayoutParams.FILL_PARENT));
    llY.addView(tvY);
</code></pre>

<p>To inflate the layout I use the following code:</p>

<pre><code>    //inflate the flipper view 
    fSpace = (ViewFlipper)findViewById(R.id.flipper);
    inflater = (LayoutInflater) getSystemService(Context.LAYOUT_INFLATER_SERVICE);
    //inflater.inflate(R.layout.yellow, fSpace); 
    fSpace.addView(llY);
    fSpace.addView(llR);
    fSpace.addView(llB);
    fSpace.addView(llG);
    fSpace.addView(llBl);
    fSpace.addView(llGr);
    fSpace.addView(llW);
</code></pre>

<p>On the main.xml I've added a scroll view which makes the text act as buttons:</p>

<pre><code>&lt;HorizontalScrollView android:scrollbars="none" 
android:layout_width="wrap_content" 
android:id="@+id/horizontalScrollView1" 
android:layout_height="wrap_content"&gt;
    &lt;LinearLayout android:layout_height="match_parent" android:orientation="horizontal" android:layout_width="match_parent" android:id="@+id/linearLayout1"&gt;
        &lt;TextView android:text="Yellow" android:layout_weight="1" android:layout_height="wrap_content" android:layout_width="70dp" android:id="@+id/EditTYellow"&gt;&lt;/TextView&gt;
        &lt;TextView android:text="Red" android:layout_weight="1" android:layout_height="wrap_content" android:layout_width="70dp" android:id="@+id/EditTRed"&gt;&lt;/TextView&gt;
        &lt;TextView android:text="Blue" android:layout_weight="1" android:layout_height="wrap_content" android:layout_width="70dp" android:id="@+id/EditTBlue"&gt;&lt;/TextView&gt;
        &lt;TextView android:text="Green" android:layout_weight="1" android:layout_height="wrap_content" android:layout_width="70dp" android:id="@+id/EditTGreen"&gt;&lt;/TextView&gt;
        &lt;TextView android:text="Black" android:layout_weight="1" android:layout_height="wrap_content" android:layout_width="70dp" android:id="@+id/EditTBlack"&gt;&lt;/TextView&gt;
        &lt;TextView android:layout_weight="1" android:layout_height="wrap_content" android:layout_width="70dp" android:id="@+id/EditTGray" android:text="Gray"&gt;&lt;/TextView&gt;
        &lt;TextView android:layout_weight="1" android:layout_height="wrap_content" android:layout_width="70dp" android:id="@+id/EditTWhite" android:text="White"&gt;&lt;/TextView&gt;
    &lt;/LinearLayout&gt;
&lt;/HorizontalScrollView&gt;
</code></pre>

<p>In the Main.java each on the buttons has a OnClickListener:</p>

<pre><code>    Yellow.setOnClickListener(this);
    Red.setOnClickListener(this);
    Blue.setOnClickListener(this);
    Green.setOnClickListener(this);
    Black.setOnClickListener(this);
    Gray.setOnClickListener(this);
    White.setOnClickListener(this);
</code></pre>

<p>Now this is where I am having the issue. Without clicking on the  menu the different TextView colors swipe from left to right with no problems. i have only added code the Yellow text so when it is click the layout should swipe back to Yellow. If I swipe over to the next color (red) and then click the Yellow text button the screen swipes back to yellow as expected.</p>

<p>If I swipe backwards to the previous screen (white also the last screen) then click on the Yellow text button the swipe animation occurs in one hit and the Yellow screen is displayed.</p>

<p>Code for the onClick is as follows:</p>

<pre><code>    public void onClick(View v) {
    // TODO Auto-generated method stub
    switch(v.getId()) {

    //--------------
    case R.id.EditTYellow:
        System.out.println("Text Yellow pressed");
        if(viewFlipper.getDisplayedChild()!=0 || viewFlipper.getDisplayedChild()&gt; 0 ){
            while (viewFlipper.getDisplayedChild()!=0  )  
             {
            viewFlipper.setInAnimation(slideRightIn);
            viewFlipper.setOutAnimation(slideRightOut);
            viewFlipper.showPrevious();
            //Delay need here to allow animation to complete
             };             
        }                       
    break;
    case R.id.EditTRed:
        System.out.println("Text Red pressed");
    break;
    case R.id.EditTBlue:
        System.out.println("Text Blue pressed");
    break;
    case R.id.EditTGreen:
        System.out.println("Text Green pressed");       
    break;
    case R.id.EditTBlack:
        System.out.println("Text Black pressed");           
    break;
    case R.id.EditTGray:
        System.out.println("Text Gray pressed");            
    break;
    case R.id.EditTWhite:
        System.out.println("Text White pressed");           
    break;
    }
}
</code></pre>

<p>I've tried to used the setAnimationListener to determine when the animation has completed and then continue with the while loop but I'm not having any success.</p>

<pre><code>        slideRightIn.setAnimationListener(new AnimationListener() {
        public void onAnimationStart(Animation animation) {

            }

        public void onAnimationRepeat(Animation animation) {

        }

        public void onAnimationEnd(Animation animation) {
          // will be called when your animation is complete 
            System.out.println("Animation End Right");
            System.out.println("Right Flipper "+viewFlipper.getDisplayedChild());
        }
    });
</code></pre>

<p>Could someone point in the right direction or tell me if I'm going about this the wrong way. Much appreciated for any feedback.</p>
