Android Animation When Changing Visiblity
<p>Long question for probably a short answer.</p>

<p>I have a series of images (displayed in a grid view) that I animate using the <em>AnimationDrawable</em> class when a button is pressed.<br />
Snippet of code for the animation;</p>

<pre><code>AnimationDrawable mAnimation;
view.setImageDrawable(null);

Random randomGenerator = new Random();
int rand = randomGenerator.nextInt(6);

BitmapDrawable frame0 = (BitmapDrawable)context.getResources().getDrawable(spinImages.get(0));
BitmapDrawable frame1 = (BitmapDrawable)context.getResources().getDrawable(spinImages.get(1));
BitmapDrawable last = (BitmapDrawable)context.getResources().getDrawable(endImages.get(rand));

mAnimation = new AnimationDrawable();
mAnimation.isOneShot();

for (int i=0; i &lt; spinNumber; i++) {
    mAnimation.addFrame(frame0, spinDuration);
    mAnimation.addFrame(frame1, spinDuration);
}
mAnimation.addFrame(last, spinDuration);

view.setBackgroundDrawable(mAnimation);
view.setTag(rand);

mAnimation.start();
</code></pre>

<p>There is also a spinner that will filter the images based on the selected value, setting some of them invisible (all works well upto this point).</p>

<pre><code>public void onItemSelected(AdapterView&lt;?&gt; arg0, View arg1, int arg2, long arg3) {

    int index = arg0.getSelectedItemPosition();
    String[] filterOptions;
    filterOptions = getResources().getStringArray(R.array.spn_options);

    // hide all below filter value
    GridView gridView = (GridView) findViewById(R.id.grid_view);
    for (int i=0; i &lt; ((ViewGroup)gridView).getChildCount(); ++i) {
        View nextChild = ((ViewGroup)gridView).getChildAt(i);
        nextChild.setVisibility(View.VISIBLE);
        if (nextChild instanceof ImageView) {
            // get tag
            if (Integer.parseInt(nextChild.getTag().toString()) &lt; arg2) {
                nextChild.setVisibility(View.INVISIBLE);
            }
            nextChild.getTag();
        }
    }
}
</code></pre>

<p>The problem is when the spinner to show all is selected I apply <code>setVisibility(View.VISIBLE)</code> on the image; which makes the images re-appear but fires the animation again. I want the image to reappear showing the final state of the animation only.</p>

<p>Any ideas?</p>
