You can use a simple default ArrayAdapter array to achieve your requirement dynamically. Below is a snippet of code that you can execute and modify your onCreate method to add values ββto the counter.
spinner = (Spinner) findViewById(R.id.spinner); ArrayAdapter<String> adapter; List<String> list; list = new ArrayList<String>(); list.add("Item 1"); list.add("Item 2"); list.add("Item 3"); list.add("Item 4"); list.add("Item 5"); adapter = new ArrayAdapter<String>(getApplicationContext(), android.R.layout.simple_spinner_item, list); adapter.setDropDownViewResource(android.R.layout.simple_spinner_dropdown_item); spinner.setAdapter(adapter);
if you want the counter values ββto be added statically, you can add an array to the xml file and assign the entries attribute to the counter. Below is a snippet of code.
Your xml file layout
<Spinner android:id="@+id/spinner" android:layout_width="fill_parent" android:drawSelectorOnTop="true" android:prompt="@string/spin" android:entries="@array/items" />
In arrays.xml file
<string-array name="items"> <item>Item 1</item> <item>Item 2</item> <item>Item 3</item> <item>Item 4</item> <item>Item 5</item> </string-array>
source share