Custom Button View states not working
<p>Using the below class and selector xml, my button simply looks like a standard button. Setting the state does not change the drawn image.</p>

<p>I simply want a view that I can change the background of at will, perhaps there would be a better approach.</p>

<pre><code>public class LayerButton extends Button{

private static final int[] STATE_NONE   = {R.attr.state_none};
private static final int[] STATE_BOTTOM = {R.attr.state_bottom};
private static final int[] STATE_MIDDLE = {R.attr.state_middle};
private static final int[] STATE_TOP    = {R.attr.state_top};
private int[] gState = STATE_NONE;
public LayerButton(Context context, AttributeSet attrs) {
    super(context, attrs);

}

public void setState(int i) {
    switch(i)
    {
    case 0:
        gState = STATE_NONE;
        break;
    case 1:
        gState = STATE_BOTTOM;
        break;
    case 2:
        gState = STATE_MIDDLE;
        break;
    default:
        gState = STATE_TOP;
        break;
    }
    refreshDrawableState();
}

@Override
protected int[] onCreateDrawableState(int extraSpace) {
    // TODO Auto-generated method stub
    final int[] drawableState =  super.onCreateDrawableState(extraSpace+1);
    if (gState != null)
            mergeDrawableStates(drawableState, gState);
    return drawableState;
}

}
</code></pre>

<p>selector below</p>

<pre><code>&lt;?xml version="1.0" encoding="utf-8"?&gt;
&lt;selector xmlns:android="http://schemas.android.com/apk/res/android" 
xmlns:app="http://schemas.android.com/apk/res/com.myapp.foo"&gt;
&lt;item
    app:state_none="true"
    app:state_bottom="false"
    app:state_middle="false"
    app:state_top="false"
    android:drawable="@drawable/layer0" /&gt;
&lt;item
    app:state_bottom="true"
    app:state_middle="false"
    app:state_none="false"
    app:state_top="false"
    android:drawable="@drawable/layer1" /&gt;
&lt;item
    app:state_middle="true"
    app:state_bottom="false"
    app:state_none="false"
    app:state_top="false"
    android:drawable="@drawable/layer2" /&gt;
&lt;item
    app:state_top="true"
    app:state_bottom="false"
    app:state_middle="false"
    app:state_none="false"
    android:drawable="@drawable/layer3" /&gt;
</code></pre>

<p></p>
