Android: Setting spinner with values from DB - but base array is in String
<p>My preset values for the spinner comes from a String Array.</p>

<pre><code>&lt;string-array name="currencyArray"&gt;
    &lt;item&gt;INR&lt;/item&gt;
    &lt;item&gt;USD&lt;/item&gt;
    &lt;item&gt;EUR&lt;/item&gt;
&lt;/string-array&gt;
</code></pre>

<p>I am able to display this and save this fine.
I am adding some values in a SQLite DB on "Add".
 On update, i want to fetch the values and display on screen. One of them is the spinner.</p>

<p>I tried this code</p>

<pre><code>String myString = getIntent().getStringExtra("Currency");
System.out.println(myString);
ArrayAdapter myAdap = (ArrayAdapter) currencySpin.getAdapter();
int spinnerPosition = myAdap.getPosition(myString);
//set the default according to value
currencySpin.setSelection(spinnerPosition);
</code></pre>

<p>The sysout (line 2) actually displays the correct value from the DB. But the spinner still displays the initial value and not the DB value.
What am i missing here?</p>

<p>I am using this code to populate and read the spinner in an empty screen</p>

<pre><code>// reading the spinner
ArrayAdapter&lt;CharSequence&gt; adapter = ArrayAdapter.createFromResource(
    this,
    R.array.currencyArray, 
    android.R.layout.simple_spinner_item);
adapter.setDropDownViewResource(android.R.layout.simple_spinner_dropdown_item);
currencySpin.setAdapter(adapter);

currencySpin.setOnItemSelectedListener(this);
</code></pre>

<p>Updated code</p>

<pre><code>            String myString = getIntent().getStringExtra("Currency");
        System.out.println(myString);

        ArrayAdapter&lt;CharSequence&gt; adapter = ArrayAdapter
        .createFromResource(this, R.array.currencyArray,
                android.R.layout.simple_spinner_item);

        spinnerPosition = adapter.getPosition(myString);
        System.out.println(spinnerPosition);

        //set the default according to value
        currencySpin.setSelection(spinnerPosition);
</code></pre>

<p>The spinnerPosition is coming as the correct number (changes from 0 to 2 as per my data), but the currencySpin (my spinner) does not display it correctly. What am i missing??</p>
