我有一個帶有 AutoCompleteTextView 作為“微調器”的 TextInputLayout。我用這樣的 ArrayAdapter 填充 AutoCompleteTextView:
val adapter: ArrayAdapter<Currency> = ArrayAdapter(requireContext(), R.layout.item_til_dropdown, currencies)
binding.currency.setAdapter(adapter)
這是我的帶有 AutoCompleteTextView 的 TextInputLayout 的 XML:
<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>
我正在努力設定所選專案。我努力了:
binding.currency.setText(currency.toString())
但這會洗掉串列中的其他專案并將當前專案單獨放入其中。
所以我的問題是如何在不洗掉其他專案的情況下設定選定專案?
uj5u.com熱心網友回復:
我通過首先設定 AutoCompleteTextView 的文本然后填充 ArrayAdapter 來解決這個問題。
轉載請註明出處,本文鏈接:https://www.uj5u.com/net/513319.html
上一篇:帶下劃線的EditText不適用于阿拉伯語(Android-Java)等某些語言
下一篇:Recyclerview選擇位置邊框會出現,未選中邊框不出現-如何在AndroidStudio中進行設計,如高亮位置
