0

I am trying to display a different value from a spinner.

Spinner initialCity =(Spinner) findViewById(R.id.initialCity);
ArrayAdapter<String> myAdapter = new ArrayAdapter<String>(SDPSalaryCalcActivity.this,
        android.R.layout.simple_list_item_1, getResources().getStringArray(R.array.fromCities));

It displays items from my string Array.

<string-array name="fromCities">

<item>city 1</item>
<item>city 2</item>
<item>city 3</item>

</string-array>

I would like instead of displaying city1 initially to display the second item.

Thank you.

ישו אוהב אותך
  • 28,609
  • 11
  • 78
  • 96
kKenny
  • 89
  • 1
  • 6
  • Couldn’t you just list them in the order you want them to appear? – 0xCursor Jun 04 '18 at 00:42
  • Have you tried `initialCity.setSelection(1)` (1 because index starts at Zero) after the you have set the adapter :: `initialCity.setAdapter(myAdapter )`? – Barns Jun 04 '18 at 00:43
  • Thank you initialCity.setSelection(1) worked. – kKenny Jun 04 '18 at 00:47
  • 2
    Possible duplicate of [Set selected item of spinner programmatically](https://stackoverflow.com/questions/11072576/set-selected-item-of-spinner-programmatically) – 0xCursor Jun 04 '18 at 00:53
  • @LAD :: Indeed you are correct. Looks like a duplicate, therefore I am removing my answer. – Barns Jun 04 '18 at 01:01

0 Answers0