Why does casting net.simonvt.numberpicker.NumberPicker to android.widget.NumberPicker work?
<p>I have an app using <code>NumberPicker</code>s. Since the app supports older versions of Android, where no <code>NumberPicker</code> widget had been available yet, I have to use an <a href="https://github.com/SimonVT/android-numberpicker" rel="nofollow">external library</a>.</p>

<p>In my XML layout <code>numberpicker_dialog.xml</code>, I define the <code>NumberPicker</code> like this:</p>

<pre><code>&lt;net.simonvt.numberpicker.NumberPicker
    android:id="@+id/interval_picker_1"
    ... /&gt;
</code></pre>

<p>Then in the code of my activity, I have:</p>

<pre><code>import net.simonvt.numberpicker.NumberPicker;

private View intervalPickerDialogBody;
private NumberPicker intervalPicker1;
private android.widget.NumberPicker api11_intervalPicker1;

protected void onCreate(Bundle savedInstanceState) {

    intervalPickerDialogBody = getLayoutInflater()
            .inflate(R.layout.numberpicker_dialog, null);

    if (Build.VERSION.SDK_INT &gt;= Build.VERSION_CODES.HONEYCOMB) {
        // the casting in question happens here
        api11_intervalPicker1 = (android.widget.NumberPicker)
                 intervalPickerDialogBody.findViewById(R.id.interval_picker_1);
    } else {
        intervalPicker1 = (NumberPicker)
                 intervalPickerDialogBody.findViewById(R.id.interval_picker_1);
    }

}
</code></pre>

<p>It works, and really on Honeycomb and newer, <code>android.widget.NumberPicker</code> is used, on older versions, <code>net.simonvt.numberpicker.NumberPicker</code> is used.</p>

<p>But now that I am writing a thesis about the app using this, I wonder:</p>

<ol>
<li>Why does casting <code>net.simonvt.numberpicker.NumberPicker</code> from the XML layout to <code>android.widget.NumberPicker</code> work when they in reality are different classes?</li>
<li>How come that only this casting makes the device use <code>android.widget.NumberPicker</code> on Honeycomb and newer when the <code>NumberPicker</code> that's in the XML layout is actually the one from the exetrnal library? When is an instance of <code>android.widget.NumberPicker</code> ever created?</li>
</ol>

<p>The fact that <code>android.widget.NumberPicker</code> is used on Honeycomb and newer is supported by the fact the second line of the forecoming code snippet equals <code>true</code> on my 4.0.3 phone.</p>

<pre><code>View tmp = intervalPickerDialogBody.findViewById(R.id.interval_picker_1);
tmp instanceof android.widget.NumberPicker // pseudocode
</code></pre>

<p>(Thank you, Jules, this is a much better proof than the striked one with the arrows. :))</p>

<p><strike>If anyone wonders how I know that <code>android.widget.NumberPicker</code> is actually used on Honeycomb and newer, it's because <code>net.simonvt.numberpicker.NumberPicker</code> doesn't display arrows above and below the <code>NumberPicker</code> as it was backported from 4.2 where the arrows have been removed. And when I try it on my device running 4.0.3, the arrows are there even though if it should display <code>net.simonvt.numberpicker.NumberPicker</code>, they wouldn't be.</strike></p>

<p>I hope the question is understandable. Thanks for elaborating on the subject.</p>
