I tried to create a simple dropdown spinner but the items does not show up when I click the spinner.
Here is my main_activity code
```
var spinner =findViewById<Spinner>(R.id.snippet)
val adapter=ArrayAdapter.createFromResource(
this,
R.array.list_units,
android.R.layout.simple_spinner_dropdown_item
)
spinner1.adapter=adapter
This is my Resource file
<array name="list_units">
Feet
Meters
Cms
</array>
This is my xml file
<Spinner
android:layout_width="wrap_content"
android:layout_height="match_parent"
android:id="@ id/snippet"/>
```
CodePudding user response:
First of all, you should define your array in ...values like this,
<?xml version="1.0" encoding="utf-8"?>
<resources>
<string-array
name="string_array_name">
<item
>text_string</item>
</string-array>
</resources>
Then import that array as string array, like this.
val values = resource.getStringArray(R.array.name_of_string_array)
and set above values
array to your array adapter.