Можно ли перевести каждый элемент массива ресурсов для отображения внутри Spinner?
(я хотел бы сохранить возможность получения значения элемента, определенного внутри массив строк ресурсов)
Расположение:
<Spinner
android:id="@+id/units_spinner"
android:layout_width="fill_parent"
android:spinnerMode="dialog"
android:layout_height="wrap_content" />
единиц. xml:
<?xml version="1.0" encoding="utf-8"?>
<resources>
<string-array name="units_array">
<item>UNIT_CAR</item>
<item>UNIT_BED</item>
<item>UNIT_SHOWROOM</item>
</string-array>
</resources>
Activity.kt:
val spinner: Spinner = findViewById(R.id.units_spinner)
// Create an ArrayAdapter using the string array and a default spinner layout
ArrayAdapter.createFromResource(this, R.array.units_array, android.R.layout.simple_spinner_item).also { adapter ->
// Specify the layout to use when the list of choices appears
adapter.setDropDownViewResource(android.R.layout.simple_spinner_dropdown_item)
// Apply the adapter to the spinner
spinner.adapter = adapter
}