I have a spinner in my app and when I click it, the related data (my string file) comes up empty.
override fun onViewCreated(view: View, savedInstanceState: Bundle?) {
super.onViewCreated(view, savedInstanceState)
ArrayAdapter.createFromResource(requireActivity(),R.array.cityList,android.R.layout.simple_spinner_item).also { adapter ->
adapter.setDropDownViewResource(android.R.layout.simple_spinner_dropdown_item)
spinner_city.adapter = adapter
}
override fun onItemSelected(parent: AdapterView<*>?, p1: View?, position: Int, p3: Long) {
val selectedCity = parent!!.getItemAtPosition(position).toString()
Log.i("Item selected?: ", selectedCity)
spinner_city.onItemSelectedListener = this
}
override fun onNothingSelected(p0: AdapterView<*>?) { }
my xml.
<Spinner
android:id="@+id/spinnerCity"
android:layout_width="match_parent"
android:layout_height="45dp"
android:layout_marginStart="32dp"
android:layout_marginTop="8dp"
android:layout_marginEnd="32dp"
android:background="@drawable/spinner_stayle"
android:gravity="start"
android:textColorHint="@color/black"
app:layout_constraintEnd_toEndOf="parent"
app:layout_constraintStart_toStartOf="parent"
app:layout_constraintTop_toBottomOf="@+id/surnameText"
android:spinnerMode="dropdown"
android:prompt="@string/selected_city"
android:entries="@array/cityList"/>
api ss
This is Simple Implementation of Spinner
And This is xml of this