Can't understand Android custom drawable state
<p>I'm new in Android development and I'm writing a small app to understand how it works. I've got all working, but at the moment I can't get a point about custom drawable states... let me explain with some sample code. </p>

<p>Here is my attrs.xml, in which I declare a attribute with name "oddMonth", which is boolean:</p>

<pre><code>&lt;?xml version="1.0" encoding="utf-8"?&gt;
&lt;resources&gt;
    &lt;declare-styleable name="DayView"&gt;
        &lt;attr name="oddMonth" format="boolean"/&gt;
    &lt;/declare-styleable&gt;
&lt;/resources&gt;
</code></pre>

<p>Then I have a custom View:</p>

<pre><code>&lt;?xml version="1.0" encoding="utf-8"?&gt;
&lt;com.example.calendar.DayView xmlns:android="http://schemas.android.com/apk/res/android"
    android:layout_width="match_parent"
    android:layout_height="90dp"
    android:background="@drawable/dayview_state" &gt;
    &lt;TextView android:id="@+id/day_number"
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:layout_alignParentTop="true"
        android:layout_alignParentRight="true"
        android:paddingRight="3dp" /&gt;  
&lt;/com.example.calendar.DayView&gt;
</code></pre>

<p>So I put the line "android:background="@drawable/dayview_state"", which refers to file dayview_state.xml:</p>

<pre><code>&lt;?xml version="1.0" encoding="utf-8"?&gt;
&lt;selector xmlns:android="http://schemas.android.com/apk/res/android" xmlns:easycalendar="http://schemas.android.com/apk/res/com.example.calendar"&gt;

    &lt;item easycalendar:oddMonth ="true" android:drawable="@drawable/customborder_odd" /&gt;
    &lt;item easycalendar:oddMonth ="false" android:drawable="@drawable/customborder_even"/&gt;

&lt;/selector&gt;
</code></pre>

<p>So far... for what I can understand.... I have a attribute defined in attrs.xml. This attribute represents the state for my custom view. According to the boolean value of this attribute my app will load one of two different xml (that are not important here), each of one defines a different drawable. So the final step is to build my custom class! Follows a extract from the class:</p>

<pre><code>public class DayView extends RelativeLayout {
    private static final int[] STATE_ODD_MONTH = { R.attr.oddMonth };
    private boolean mOddmonth = true;

    public DayView(Context mContext, AttributeSet attrs) {
        super(mContext, attrs);
    }

    @Override
    protected int[] onCreateDrawableState(int extraSpace) {
        if (mOddmonth) {
            final int[] drawableState = super.onCreateDrawableState(extraSpace + 1);
            mergeDrawableStates(drawableState, STATE_ODD_MONTH);

            return drawableState;
        } else {
            return super.onCreateDrawableState(extraSpace);
        }
    }

    public boolean isOddMonth() {
        return mOddmonth;
    }

    public void setOddMonth(boolean oddMonth) {
        if (mOddmonth != oddMonth) {
            mOddmonth = oddMonth;

            refreshDrawableState();
        }
    }
}
</code></pre>

<p>Ok... so I have here a private variable mOddMonth, whith getter and setter. The constructor which is used to inflate this view elsewhere. Another private variable:</p>

<pre><code>private static final int[] STATE_ODD_MONTH = { R.attr.oddMonth };
</code></pre>

<p>which is a array made up of only one int value, that is a reference to the attribute oddMonth defined in attrs.xml. And the inherited method:</p>

<pre><code>@Override
    protected int[] onCreateDrawableState(int extraSpace) {
        if (mOddmonth) {
            final int[] drawableState = super.onCreateDrawableState(extraSpace + 1);
            mergeDrawableStates(drawableState, STATE_ODD_MONTH);

            return drawableState;
        } else {
            return super.onCreateDrawableState(extraSpace);
        }
    }
</code></pre>

<p>which I can't really "deeply" understand... well, it seems to me that I add a state if the local variable mOddMonth is true, otherwise not. So... my code works only if I replace my dayview_state.xml with the following:</p>

<pre><code>&lt;?xml version="1.0" encoding="utf-8"?&gt;
&lt;selector xmlns:android="http://schemas.android.com/apk/res/android" xmlns:easycalendar="http://schemas.android.com/apk/res/com.example.calendar"&gt;

    &lt;item easycalendar:oddMonth ="true" android:drawable="@drawable/customborder_odd" /&gt;
    &lt;item android:drawable="@drawable/customborder_even"/&gt;

&lt;/selector&gt;
</code></pre>

<p>In this way the first layout is loaded if THERE IS the state, otherwise will be loaded the second one. But WHAT ABOUT THE VALUE of the state? Nowhere in my code I set the value for this variable/attribute.... where I'm wrong?</p>
