title: How to change a layer-list drawable?
body: <p>Trying to learn some new things and can't figure this one out, any help is appreciated. Given this simple code which is right from Google's documentation:</p>
  
  <p>layers.xml:</p>
  
  <pre><code>&lt;?xml version="1.0" encoding="utf-8"?&gt;
  &lt;layer-list xmlns:android="http://schemas.android.com/apk/res/android"&gt;
      &lt;item android:id="@+id/first_image"&gt;
        &lt;bitmap android:src="@drawable/android_red"
          android:gravity="center" /&gt;
      &lt;/item&gt;
      &lt;item android:id="@+id/second_image" android:top="10dp" android:left="10dp"&gt;
        &lt;bitmap android:src="@drawable/android_green"
          android:gravity="center" /&gt;
      &lt;/item&gt;
      &lt;item android:id="@+id/third_image" android:top="20dp" android:left="20dp"&gt;
        &lt;bitmap android:src="@drawable/android_blue"
          android:gravity="center" /&gt;
      &lt;/item&gt;
  &lt;/layer-list&gt;
  </code></pre>
  
  <p>And main.xml:</p>
  
  <pre><code>&lt;ImageView
      android:id="@+myImageView"
      android:layout_height="wrap_content"
      android:layout_width="wrap_content"
      android:src="@drawable/layers" /&gt;
  </code></pre>
  
  <p>Question: How do I programmatically reference one of the drawables in the layer-list so I can change it to a different drawable?</p>
  
  <p>Thanks.</p>
  
  <p>So now I have my new drawable that I want to swap in in variable <code>myImage</code> correct? Now how do I get that into the layer-list? I assume I use <code>findDrawableByLayerId</code> and <code>setDrawableByLayerId</code>, but how exactly? Or I could be doing it completely wrong! Help!</p>
  
  <p>What am I trying to do? Change the drawable that's displayed. For example suppose I had another drawable called "android_purple", how would I switch it in for the "android_green" drawable in the layer-list example above? </p>
  
  <p>EDIT:</p>
  
  <p>With my limited knowledge here is my code so far (which does <em>not</em> work, I get error that <code>setDrawableByLayerId</code> is undefined):</p>
  
  <pre><code>Resources res = getApplicationContext().getResources();
  BitmapDrawable newImage = (BitmapDrawable) res.getDrawable(R.drawable.android_purple); //Get replacement image, can't use LayerDrawable or get error.   
  boolean layer_drawable_changed = (setDrawableByLayerId((R.id.second_image), newImage)); //Set new drawable? Error on this line.
  </code></pre>