title: Programmatically Using Androids Loading Spinners
body: <p>I'm currently wanting to use the Android's system Spinners, which is located at <code>..\sdk\platforms\android-19\data\res\</code></p>
  
  <p>I currently have the .png files example <code>spinner_white_48.png</code> </p>
  
  <p>and animation xml <code>progress_medium_holo.xml</code>:</p>
  
  <pre><code>&lt;layer-list xmlns:android="http://schemas.android.com/apk/res/android"&gt;
      &lt;item&gt;
          &lt;rotate
               android:drawable="@drawable/spinner_48_outer_holo"
               android:pivotX="50%"
               android:pivotY="50%"
               android:fromDegrees="0"
               android:toDegrees="1080" /&gt;
      &lt;/item&gt;
      &lt;item&gt;
          &lt;rotate
               android:drawable="@drawable/spinner_48_inner_holo"
               android:pivotX="50%"
               android:pivotY="50%"
               android:fromDegrees="720"
               android:toDegrees="0" /&gt;
      &lt;/item&gt;
  &lt;/layer-list&gt;
  </code></pre>
  
  <p>The following does not work:</p>
  
  <pre><code>         // Load the ImageView that will host the animation and
           // set its background to our AnimationDrawable XML resource.
           ImageView img = new ImageView(context);
           img.setBackgroundResource(my.package.R.drawable.progress_medium_holo);
  
           // Get the background, which has been compiled to an AnimationDrawable object.
           AnimationDrawable frameAnimation = (AnimationDrawable) img.getBackground();
  
           // Start the animation (looped playback by default).
           frameAnimation.start();
  </code></pre>
  
  <p>I am receving the error now:</p>
  
  <pre><code>12-05 23:31:15.731: E/AndroidRuntime(30685): java.lang.ClassCastException: android.graphics.drawable.LayerDrawable cannot be cast to android.graphics.drawable.AnimationDrawable
  </code></pre>
  
  <p>I cannot find any info on how to programmatically implement these.</p>