Recently, I was workin on a project where I have had a Spinner
with a small number of values.
The values were static, and I stored them into an array in the resources.
<string-array name="my_array">
<item>Value 1</item>
<item>Value 2</item>
<item>Value 3</item>
<item>Value 4</item>
</string-array>
Populating the Spinner
using the ArrayAdapter
was pretty straight forward (for more info, check: Android Developer: Spinners),
but I know that the Spinner
can be also populated by adding android:entries="@array/my_array"
in the .xml directly.
ArrayAdapter
was always my choice when it comes to populating Spinner
, but I'm wondering, what are some best practices, are there any downsides populating such a simple spinner directly in the .xml, because it would make a class with less code, cleaner and more readable?