Spinner set selection by id
<p>My application has records. Records has categories. In edit record activity I need set category of record to Spinner by categoryId. I found solution like below:</p>

<pre><code>for (int i = 0; i &lt; spinner.getCount(); i++) {
    Cursor value = (Cursor) spinner.getItemAtPosition(i);
    long id = value.getLong(value.getColumnIndex("_id");
    if (id == rowid) {
        spinner.setSelection(i);
    }
}
</code></pre>

<p>but it is a bad solution. It will be slow, because I do not have any amount limits for category in my application.</p>

<p>Do you have any solutions?</p>

<p>Thanks a lot!</p>
