in kotlin I did it that way
<string-array name="coins_array">
<item>USD</item>
<item>USDT</item>
</string-array>
import android.os.Bundle
import android.view.View
import android.widget.AdapterView
import android.widget.ArrayAdapter
import android.widget.Toast
import androidx.appcompat.app.AppCompatActivity
import kotlinx.android.synthetic.main.main_activity.*
class MainActivity: AppCompatActivity(), AdapterView.OnItemSelectedListener{
private var touchEvent = false
override fun onCreate(savedInstanceState: Bundle?) {
super.onCreate(savedInstanceState)
setContentView(R.layout.main_activity)
ArrayAdapter.createFromResource(this, R.array.coins_array, android.R.layout.simple_spinner_item
).also { adapter ->
adapter.setDropDownViewResource(android.R.layout.simple_spinner_dropdown_item)
coin_choice.adapter = adapter
}
coin_choice.onItemSelectedListener = this
}
override fun onItemSelected(parent: AdapterView<*>, view: View, position: Int, id: Long) {
if(touchEvent){
val coin: String = parent.getItemAtPosition(position).toString()
Toast.makeText(this, coin, Toast.LENGTH_SHORT).show()
}
touchEvent = true
}
override fun onNothingSelected(parent: AdapterView<*>?) {
}
}