I have a TextInputLayout with AutoCompleteTextView as a 'Spinner'. I populate the AutoCompleteTextView with an ArrayAdapter like this:
val adapter: ArrayAdapter<Currency> = ArrayAdapter(requireContext(), R.layout.item_til_dropdown, currencies)
binding.currency.setAdapter(adapter)
This is my XML for the TextInputLayout with the AutoCompleteTextView:
<com.google.android.material.textfield.TextInputLayout
android:id="@ id/currency_til"
android:layout_width="0dp"
android:layout_height="wrap_content"
android:layout_marginTop="@dimen/textinputlayout_margin"
android:hint="Currency"
app:boxBackgroundColor="@android:color/transparent">
<AutoCompleteTextView
android:id="@ id/currency"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:clickable="true"
android:focusable="true"
android:focusableInTouchMode="false"
android:inputType="none" />
</com.google.android.material.textfield.TextInputLayout>
I'm struggling to set the selected item. I have tried:
binding.currency.setText(currency.toString())
But this removes the other items in the list and puts the current one in it alone.
So my question is how do I set the Selected Item without it removing the other items?
CodePudding user response:
I solved this by first setting the text of the AutoCompleteTextView then after that populating the ArrayAdapter.