title: Animating custom CheckedTextView when clicked with AnimationDrawable
body: <p>I want to add some kind of Material look to my checkboxes. I want the checkmark drawable to animate from one state to another, using custom drawables. I tried to animate both an <code>ImageView</code> (to see if it works) and a <code>CheckedTextView</code> (which is what I really need).</p>
  
  <p>In order to do this I created both views in my layout, and set <code>android:onClick</code> to a custom method, respectively <code>animateImage(View v)</code> and <code>animateChecked(View v)</code>. My problem is that the second does NOT work, despite the only difference between the two is how I get and set the drawable I need.</p>
  
  <p><strong>layout.xml</strong></p>
  
  <pre><code>&lt;ImageView
      android:layout_width="50dp"
      android:layout_height="50dp"
      android:layout_gravity="center"
      android:src="@drawable/checkbox_off" &lt;!-- static png showing the unchecked mark --&gt;
      android:clickable="true"
      android:onClick="animateImage"/&gt;
  
  &lt;CheckedTextView
      android:layout_width="match_parent"
      android:layout_height="wrap_content"
      android:text="@string/impo8"
      android:gravity="center_vertical|left"
      android:checked="false"
      android:clickable="true"
      android:CheckMark="@drawable/checkbox_off" &lt;!-- again --&gt;
      android:onClick="animateChecked" /&gt;
  </code></pre>
  
  <p><strong>activity</strong></p>
  
  <pre><code>public void animateImage(View v) {
      ImageView iv = (ImageView)v;
      iv.setBackgroundResource(R.drawable.animation_checkbox_on);
      AnimationDrawable adOn = (AnimationDrawable)iv.getBackground();
      adOn.setColorFilter(getResources().getColor(R.color.static), PorterDuff.Mode.SRC_IN);
      adOn.start();
  }
  public void animateChecked(View v) {
      CheckedTextView c = (CheckedTextView)v;
      c.setCheckMarkDrawable(R.drawable.animation_checkbox_on);
      AnimationDrawable ad = (AnimationDrawable) c.getCheckMarkDrawable();
      ad.setColorFilter(getResources().getColor(R.color.static), PorterDuff.Mode.SRC_IN);
      ad.start();
  }
  </code></pre>
  
  <p>Of course <strong>animation_checkbox_on</strong>, used in both methods, is an animation-list xml resource with static pngs and duration. I wanted to keep this as simple as possible (not even implemented an "if checked" statement).</p>
  
  <p>As said: the first method works and ImageView gets animated correctly; the second method does NOT work, and the checkmark remains still. Is there some kind of conceptual error in my code, or am I wrong somewhere? How can I make this work on a <code>CheckedTextView</code> mark?
  I don't get any warning from Android Studio. Thank you.</p>
  
  <p><strong>/drawable/animation_checkbox_on</strong></p>
  
  <pre><code>&lt;?xml version="1.0" encoding="utf-8"?&gt;
  &lt;animation-list xmlns:android="http://schemas.android.com/apk/res/android"
  android:oneshot="true"&gt;
  &lt;item
      android:drawable="@drawable/checkbox_off2" android:duration="50" /&gt;
  &lt;item
      android:drawable="@drawable/checkbox_off3" android:duration="50" /&gt;
  &lt;item
      android:drawable="@drawable/checkbox_on" android:duration="50" /&gt;
  </code></pre>
  
  <p></p>
  
  <p><strong>EDIT:</strong>
  I noticed that the first item in the animation-list gets actually loaded. Also, the result is the same if I delete the line <code>ad.start()</code> (!).</p>
  
  <p>It looks like either <code>setCheckMarkDrawable</code> or <code>getCheckMarkDrawable</code> return just the first item of the animation-list, thus making ineffective <code>ad.start()</code>, and transforming the animation into a simple drawable switch.
  If this is true the question would be how to animate a CheckedTextView. I've read about manually pausing the thread for some time before applying next drawable, but that doesn't seem the best option to me.</p>